390 likes | 795 Views
ArcView / Avenue / ArcGIS Customization. Basic Customization in ArcView 3.x. Sources for scripts and extensions Installing an extension Adding and running a script Attaching a script to a button System scripts Startup and shutdown scripts. Sources for Scripts & Extensions.
E N D
Basic Customization in ArcView 3.x • Sources for scripts and extensions • Installing an extension • Adding and running a script • Attaching a script to a button • System scripts • Startup and shutdown scripts
Sources for Scripts & Extensions • ArcScripts (http://arcscripts.esri.com/) • Sample Scripts and Extensions in the ArcView help (look under Sample scripts and extensions in the table of contents) • Google • Online communities • http://www.directionsmag.com/files/ • http://software.geocomm.com/scripts/arcview/
Installing an Extension On a Windows machine: • Put the .avx file in the c:\esri\av_gis30\arcview\ext32 directory • You can also set the USEREXT environment variable to use another location (if you have admin privileges)
Installing an Extension On our UNIX system: • Putting the .avx file in your home directory should make ArcView see it when you are logged in • Or you can set an environment variable called USEREXT to point to a custom location and then put all your .avx files in that location • Only the system administrator can install an extension so all users can see it
Adding a Script • In the ArcView Project window, select the Scripts icon and then click New • Either type, paste, or use the Script | Load Text File option to get your code in the new script window • Use Script | Compile or the checkbox button to compile the script • If you don’t get an error message, then the script compiled successfully
Running a script • Some scripts can be run from the project window, just by clicking Run • Others might need to be associated with a particular (open) document, like a view • To associate a script with a view: • Open the script • Activate the necessary view • Activate the script • Choose Script | Run
Running a script • A better way to make a script work with a view if you’re going to use it a lot is to put a new button on the View toolbar and associate it with the script • Make a view active • Double-click on an empty part of the toolbar • Make sure Type is View and Category is Buttons • Select a button and click New (this will create a new button next to the one you selected)
Running a Script • Select your new button • Double-click on the empty box next to Click (in the bottom part of the dialog) • Select the script you want to run • You can also set an icon for the button by double-clicking on the Icon section at the bottom of the Customize dialog
System Scripts • A lot of the scripts written by ESRI are available for you to use • Use the customize dialog to see what script gets run by a button or menu item • You can attach system scripts to your own custom buttons
You can make a script automatically run when you open or shut down a project Choose Project | Properties Set scripts using the script selection buttons You can also set a working directory and a selection color using this dialog Startup and Shutdown Scripts
Calculators • Field calculator (attribute data) • Shape calculations • Number calculations • String calculations • Map calculator (raster data)
To see a list of requests available for a data type, click the appropriate Type radio button and then scroll down the Requests list The example shown here converts a numeric ID to a string and puts it in a new field called NewField1 Field Calculator
Field Calculator • Operations on shapes are not shown in the Field Calculator itself • To see what shape requests are available, open the ArcView help and go to the Shape (class) entry in the index • You can’t use everything that is listed, but you can use the ones that return a number, string, or boolean and don’t require another shape (so you can use ReturnArea but not Contains)
You’ll have to type the request in yourself (don’t forget the period between [Shape] and the request!) This example computes the area of a shape (polygon) and puts it in a field called NewField1 Field Calculator
Field Calculator • Descriptions of all requests are in the ArcView help; either search on the name of the request you see in the dialog, or go to the following pages in the index to see a list of them all: • Shape (class) • Number (class) • String (class) • Date (class)
Field Calculator Examples • Autonumber records: rec + 1 • Convert a number to string: [num].AsString • Concatenate two string fields into one: • [str1] + [str2] (no space) • [str1] ++ [str2] (space between originals) • Extract first 3 characters from a string: [str].Left(3)
Field Calculator Examples • Convert a number to a string: [num].AsString • Compute absolute value of a number: [num].Abs • Get the maximum of two numeric fields: [num1] max [num2]
Double-click on a grid name and then you’ll be able to select request types from the list Use the AsGrid request to convert numbers to grids This example takes the base10 log of Grid1 and then adds 5 to that Map Calculator
Map Calculator Examples • Create a grid that has true everywhere grid1 is NULL and false where grid1 has data: [grid1].IsNull • Create a grid that has values from grid1 where grid3 is non-zero and values from grid2 everywhere else: [grid3].Con([grid1],[grid2]) • Mosaics 3 grids together: [grid1].Mosaic({[grid2],[grid3]}) • Check out the Grid (class) section in the help to see more requests
Basic Customization in ArcGIS • Normal template • Making your own toolbar • The Visual Basic Editor • Adding and running a Visual Basic script • Attaching a script to a button • Keyboard shortcuts
Normal Template • Stores information (including customizations) for the ArcGIS application • Anything saved in normal.mxt is available in all map documents • Make sure you save customizations in the correct place (normal.mxt for global customizations, your .mxd file for project-specific customizations)
Making Your Own Toolbar • Open the Customize dialog by either double-clicking on an empty spot in the toolbar or choosing Customize from the Tools menu • Go to the Toolbars tab and click New • Name your toolbar and choose the location to save it • Your new toolbar will open when you click OK
You can change the tooltip or icon, or delete a tool on your toolbar by right-clicking on it while the Customize dialog is open Go to the Commands tab in the Customize dialog Drag the commands you want onto your toolbar Making Your Own Toolbar
Open the Visual Basic Editor by choosing Tools | Macros | Visual Basic Editor The Project window shows all of the code VB code available in the current project Code can be in normal.mxt or in the current project Code that you’re adding will most likely be in a regular Module The Visual Basic Editor
Adding a Visual Basic Script • Open the Visual Basic Editor • Right-click on one of the Module folders and either import the file or insert a new Module • If you didn’t import the file, paste the code into the new Module • Make sure the code compiles by choosing Debug | Compile Project
Running a Visual Basic Script • From the Visual Basic Editor, choose Run | Run Sub/UserForm while your cursor is in the procedure you want to run • From ArcMap, open the Macros dialog by choosing Tools | Macros | Macros, and then select the procedure you want to run and click Run
Attaching a Script to a Button • Open the Customize dialog • Go to the Commands tab • Go to the Macros category • Drag the macro you want to attach to a toolbar • Right-click on your new tool to change tooltips and icons
Creating a Tool with Unique Code • Sometimes you might want to create a button that runs code specific to it (rather than contained in a separate module) • Open the Customize dialog and go to the Commands tab • Select the UIControls category and click New UIControl • Make sure UIButtonControl is selected and click Create
Creating a Tool with Unique Code • You can change the name of your control by clicking on it twice (slowly) • Drag the tool to a toolbar • Right-click on the new button and choose View Source in order to view (and edit) the code
Keyboard Shortcuts • Open the Customize dialog and click on the Keyboard button • Select the command you want to create a shortcut for • Put your cursor in the Press new shortcut key box and press the key combination you want to use • You will see if that combination is already assigned (Currently assigned to section) • If you want to use that combination, click Assign
Basics of Avenue Programming • Basic concepts • Classes and objects • Avenue requests to find objects • Places to get help
Basic Avenue Concepts • Object oriented, which means you have a collection of objects that you send requests to • There are many classes of objects (views, themes, etc), and more than one object of each class can exist • Think of a particular object as a (really smart) variable and its class as a data type
Basic Avenue Concepts • An object is smart enough to do its own processing, which is why you send requests to it (you tell a theme to turn itself on, for example, rather than telling the main ArcView application to turn a specific theme on) • Before you can do any processing, you need to get a “handle” to the object you want to do processing on
Basic Avenue Concepts • For example, if you want to turn a theme on, you: • Find the View • Find the Theme • Make the theme visible myView = Av.FindDoc(“View1”) myTheme = myView.FindTheme(“Theme1”) myTheme.SetVisible(true) Av.FindDoc(“View1”).FindTheme(“Theme1”).SetVisible(true)
Avenue Requests to Find Objects • To find a view: myView = Av.FindDoc(“view_name”) • To find a theme: myTheme = myView.FindTheme(“theme_name”) • To get a vector theme’s attribute table: myTable = myTheme.GetFTab • To get a field in an attribute table: myField = myTable.FindField(“field_name”)
Places to Get Help • ArcView Help • http://support.esri.com (the User Forums, Knowledge Base, and Downloads sections) • Listservs at http://lists.directionsmag.com/discussion/