Adding a Script to an ArcView Project



Adding Scripts to Projects

Since ArcView does not do all of the processing that you need, you will sometime need to add functionality. This is done through Avenue scripts. Avenue is the proprietary language associated with ArcView. This is not a programming workshop and, therefore, we will have to add a script. Not worry - the script is already written.


The Script

The purpose of the script to find the watershed above a certain point in a Digital Elevation Model. The code can be found at /mit/gis/programs/avenue/watershed.ave

If you are a programmer and interested in how this works, feel free to look at the code and read the paragraph below. Otherwise, skip this section and move on to "Add the Script to the Project."

The script does several bookkeeping steps:


Adding the Script to the Project

To add the script to the project:

  1. Make the Scripts the active document type. You do this by making the project window active and then highlighting Scripts by clicking on its icon.
  2. Create a new script window by clicking on the New button.

    Result: AScript window appears.  Notice the new menus, buttons, and tools that are available when a Script is the active document.  The following three three buttons used for getting and writing out scripts: . The first button is for loading system scripts into the current script window. The second button is for loading scripts stored on Athena as text files.  The third button is for witing scripts as UNIX text files.

  3. To add a text file, click on the second button.

    Result: The Load Scripts dialog box appears.

  4. Navigate to /mit/gis/programs/avenue/.
  5. Select watershed.ave.
  6. To compile the program, from the Scripts menu, choose Compile. This is more of a lint cleaner function since the code is not actually compiled but is checked for syntax errors.

    Result: you have a compiled script that you can now associate with a button on the ArcView GUI.

  7. From the Scripts menu, select Properties.

    Result: The Script1 Properties dialog box appears.

  8. Change the name of the script to _watershed and click on OK

    Note: By starting the filename with a "_", will you will be able to find your script from the long list of system scripts.

Now you are ready to add the script to the toolset.

Attaching a script to a tool

To get the Custoimize dialog box interface, double click in the area to the right of the button or tool controls .  You will use this interface to add buttons and tools and associate scripts with the buttons and tools.  When you click on the tool, the script you associated with the tool will be run when you click on the view.  This is what the Customize interface looks like:

Arcview allows you to add widgets (menus, buttons, tools, and popups) to all of the document types that Arcview supports (View, Table, Chart, Layout, Script, Project, and Application).  In this exercise we will add a button to the View interface.  Depending on which document type is active,  you may need to

Create a new tool  and associate the new script with the tool.

  1. Click on tool.

    Result: a new tool is created on the toolbar.

  2. Click on apply.

    Result: the Script Manager dialog box appears.  From the list of system scripts and any scripts you may have added, choose _watershed.  Your script should be easy to find at the end of the list of scripts since you have a special character as the first character of its name.

  3. Double click on the Help component and type a help message ("Find the watershed above a point on the view") in the dialog box that appears.
  4. Add an icon by clicking on the icon property and selecting one of the stock icons from the dialog box that appears.


Close the Customize dialog box.


Running the Script

Now make the view containing the Ashfield_nos DEM the active window.  You should need to have the Flow Direction grid in this window. You may only see a small watershed above the point you selected. Refine this by looking for stream channels and finding the watershed above the point on the stream 


MIT Information Systems Comments about these pages