skip to page content | skip to main navigation
 Catalog and Search Tools  Research Help   Libraries and Collections  Services  How To ...  About SULAIR
Geographic Information Systems (GIS)
Printer-Friendly Printer-Friendly

How to add a script in ArcView

There are many script resources out there: sample scripts from ESRI included with ArcView, free scripts that you can download at ESRI's ArcScripts website, and scripts that you may receive from other GIS users.  Sometimes these scripts may come with text files describing how to use them, but often  they do not.  This page will help you get started with using scripts.  Included are instructions for how to load, compile, and run scripts, and also how to add a custom button associated with a script to the View interface.


The first step in using your script is to load it into your project.; In this example, you'll add a Sample Script that comes with ArcView. This script adds X and Y coordinates for every feature into your shapefile's attribute table. The first step is to open a New Script window in the Project window, as shown below:

Load the sample script into this new script window, by going to the Script Menu --> Load Text File.  If we wanted to customize a System Script (something you might do once you are quite comfortable with Avenue), you would use the Load System Script menu entry.  Write Text File is used to save your scripts to a text file; otherwise, your scripts are only saved within your ArcView project file (.apr file).

If you have ArcView loaded in the default location, the ArcView sample scripts are found in the following directory: C:\ESRI\AV_GIS30\ArcView\Samples\Scripts.  Avenue scripts are text files with a .ave extension.

Once a script is loaded, or after you have written or edited a script, you need compile it.  Compiling the script means that ArcView goes through the entire script, looks for syntax errors, and translates the script into a form that ArcView can use.  To compile a script, simply press the Compile button (the black checkmark) or go to Script> Compile in the menus.  Sample scripts should readily compile.  If you are writing your own Avenue script, you may have syntax errors that you will then need to go through and fix before your script will properly compile.

Now you can rename your script and add comments to allow you and other users to know something about the script.  Go to Script --> Properties to change the name to something more descriptive than Script1 (just as you would use Theme Properties and View Properties to rename your themes and views).

Once you have successfully compiled your script, you can run it in one of several ways. 

1. You could press the run button next to the compile button while the script is active.
2. You could press the run button next to the Open button in the Project window (the same window where you first opened up your new script window)
3. You could add a custom button to your View interface from which you can run your script.(Shown Below)

To add a custom button, you first need to open up the Customize Dialog Box.  To do this, double click in the gray area of the button bar in the main ArcView interface, as shown below.

You will now see the Customize dialog box, and can view the properties of existing buttons and menus, as well as add your own. When this dialog first opens, the default Category is "Menu"; switch this Category to "Buttons."  You'll see all of the existing buttons display, and you can scroll along to where you want to place you new button, then click "New."  Click on some of the existing buttons and look at their attributes ("Click", "Disabled", "Help", "Icon", etc) to get a feel for how the buttons work.  It is here that you attach the script to the button, as shown below.

Each button is associated with a script that runs when a user clicks the button.  The "Click" attribute contains the name of this script.  A new button has an empty Click attribute by default, but by clicking on this attribute you can bring up a dialog box to choose the script you want to associate with the new button.

Double click on the Icon field to choose your icon for your new button.

You can add text into the Help dialog box to specify what you want the user to see as a yellow po-up text when the user puts the mouse over the new button, as well as what text will appear in the lower right hand corner of the ArcView application window. 

When entering your text into this Help Dialog box, the first text is what will appear when you move your mouse over the button, and the text following the two forward slashes is what will appear in the lower right hand corner (generally more descriptive text), as you can see in the following figure.

Make your shapefile active in your view, and then press your new button to
execute the script AddXYCoordinates.&nbsp; Open the table and scroll to the end of the fields, and you will see the two new fields added by the script, <i>X-coord</i>and <i>Y-coord</i>, and the XY coordinates for each feature in the units of the shapefile (here, decimal degrees for Latitude and Longitude).

Now you know the basics of adding scripts in ArcView!

Last modified: June 24, 2005

seal © Stanford University. Stanford, CA 94305. (650) 723-2300. Terms of Use | Copyright Complaints