Thirty Tips and Tricks for Programming in Avenue

Marco Morais

Updated:

Some tips and tricks for customizing ArcView 3x using Avenue

User Interface Modifications

  1. You cannot have a tool selected and invisible at startup as of ArcView version 3.1.
  2. A common symptom of menu bars without menu items is that the portion of the screen occupied by the menu bar is not refreshed properly. To force ArcView to refresh the menu bar display you must have at least one menu item present on the menu bar, even if it is invisible.
  3. To delete custom icons from the icon list do the following. First, get a reference to the icon using the name dictionary. Next, clone the existing system icon dictionary and take the returned key-value pair from step one to remove the entry in the dictionary. Copy this new dictionary, minus one icon, back into the system icon dictionary.
  4. Making the legend of themes in the View invisible can be a useful technique for making the the View document TOC appear less cluttered, particularly when there are a lot of themes in a View.
  5. Tool tips can be generated by placing two forward slashes (\) followed by the tool tip text in the help string associated with a control.
  6. When developing a GUI, take a screen shot and mark it up with the names of scripts associated with each control to facilitate organizing the scripts associated with a particular document.
  7. Stacks are useful data structures to use to remember previous user actions and enable “undo” functionality in your applications.
  8. The Activate request associates a GUI with a document for one time only. The next time the document is opened the original GUI will be associated with it.
  9. The project table of contents window, the window from which you manage all of the Views, Tables, Charts, Layouts, and Scripts, can have the width of its table of contents (TOC) modified. This is particularly useful if you introduce a new document type that has a unique icon to display in the TOC. However, modifications to the project document window width must be restored to the original default width prior to closing the project to avoid crashing ArcView.

    Data Loading and Query

  10. The only way to check if a filename is valid for a datasets is to use the static File.Exists(SrcName.AsFileName) request.
  11. The GetFullName request is useful for expanding filenames which have an environment variable into full pathnames free of the environment variable.
  12. To select all of features within “x” distance of the currently selected features use the SelectByTheme request with the same theme as controlling object and in the argument list.
  13. If you want to preserve an existing selected set, clone the bitmap prior to performing the new selections. When finished, copy the cloned bitmap back to restore the originally selected set.
  14. There are two types of bitmaps, selection and definition, which corresond to the query and definition items in the “Theme Properties” dialog. The former causes selected features to display with the selected color, yellow by default. The latter limits the display of features to only those in the selected set.

    Extensions

  15. A persistent dictionary is associted with every extension object called the extension preferences dictionary. Use this dictionary to store persistent global properties used by your extension.
  16. Use the the $HOME environment variable to define a directory to store your extensions. When launched, ArcView will search for extensions in multiple locations, including the directory associated with the $HOME environment variable as well as the ext32 subdirectory in the ArcView installation directory. You can set this environment variable in Windows 95 and 98 using the autoexec.bat file and in Windows NT from the System->Properties->Environment tab in the Control Panel.
  17. Whenenver you modify the default document graphical user interface (GUI), you will have to write a script to reload the original, unmodified GUI when it comes time to close the extension. One option is to write the existing controls, which themselves may contain modifications of the default document GUI, to a temporary object (ODB) file on disk. When you unload the extension, open the ODB file and reload the user’s original GUI. Remember to delete the temporary ODB file you created.

    Scripts

  18. When passing arguments to scripts that are single objects, use the SELF keywrd to retrieve the object inside of the called script. In contrast, arguments passed as lists must be retrieved by index eg SELF.Get(2).
  19. Always use “return NIL” at the conclusion of your scripts rather than “exit”, which terminates the current script as well as any other executing scripts.
  20. The av.FindScript() request is more comprehensive than av.GetProject.FindScript().

    Avenue

  21. The ExecuteSyncronous request should be used with system commands if you need to use the outcome of the system command immediately.
  22. There is a limit to the number of charcters supplied to the System.Execute request. Use a batch file if you must excede this limit.
  23. If an object has been copied to the clipboard during its lifetime, then purge the clipboard of its associated objects prior to deleting it to avoid an ArcView crash.
  24. Remember to use the av.GetProject.SetModified(true) request whenever modifying GUIs or deeleting themes from a document via Avenue.
  25. To limit the amount of error checking in your code use the Update property associated with controls to enable or diable the script from being called under inappropriate conditions.
  26. List data structures must be cloned before you can delete mutable objects otherwise you will get an array access error.
  27. The SetDynamicBreak request can be used for conditional debugging such as when you want to break at the 10th iteration in a loop rather than the first iteration.
  28. ObjectTags associated with controls, documents, themes, and graphics provide another means for persistent storage of objects. Since they remain even when project is saved and closed, use this mechanism only when necessary to avoid the accumulation of these objects and subsequent ballooning of project files.

    Dialogs

  29. When using dialogs created from the dialog document type you must have the dialog designer extension (avdlog.avx) loaded, otherwise, when dialogs are created directly from Avenue code, you only need to have avdlog.dll and avdlog.dat in the system path to create dialogs.
  30. Use the Flush request before launching a modal dialog over a Display object to prevent ghosting behind the dialog should the user move the dialog around.

See Also

Photo of author
About the author
Marco Morais