How To: Emulate sort order buttons in the Legend Editor through Avenue


The information in this article applies to ArcView GIS versions 3.x only. The instructions described apply to the Avenue programming language, which is specific to the ArcView GIS application.

There are several dialog boxes in the ArcView GIS interface that have no Avenue counterparts. These dialog boxes were written in C++ and were not based on Avenue. Changing the sort order of the Legend symbols and classifications falls into this category.


The following Avenue script emulates the C++ version of the buttons in the Legend Editor dialog box.

  1. Open a new script window.
    1. Activate the Project window.
    2. Click the Scripts icon.
    3. Click New.
  2. Copy the following code into the script window:
'-------------------------- BEGIN SCRIPT --------------------------------
' The script should be attached to a button on the View graphical user interface (GUI). The script 
' will alternate between sorting ascending and descending. Modify the script to suit your needs.
' This script reverses the order of the Legend Symbols and Classification.
' This script is analogous to the Ascending and Descending buttons in
' the Legend Editor.
theview = av.getactivedoc
thetheme = theview.getthemes.get(0)
thelegend = thetheme.getlegend

' A classification consists of the range of values and the label for a single 
' symbol. Only the label is displayed in the themes legend.
theclassificationlist = thelegend.getclassifications

' The last classification in theclassificationlist is for No Data.
' Therefore, you need to skip past no data and get the count of theclassificationlist and hence - 2 instead of - 1.
maxclass = theclassificationlist.count - 2 

count = 0

' You must clone the list of symbols and classifications; otherwise, the legend
' will have an inverted look to it (i.e., the last symbol and classification
' will overwrite the first symbol and classification in real time). When it 
' comes time to overwrite the last symbol and classification with the
'first symbol, the first symbol will have already been overwritten. What you really
' want is a clone of the original first symbol and classification to overwrite
' the last symbol and classification.
clonedlist = thelegend.getclassifications.clone
clonedlist2 = thelegend.getsymbols.clone

for each i in theclassificationlist

 ' You do not want to consider the No Data symbol and classification when
 ' overwriting the Legend components.
 if (count < (theclassificationlist.count - 1)) then
  ' You need to change BOTH the Legends symbol and classification to
  ' replicate the sort order buttons in the Legend Editor. You may want to 
  ' experiment with commenting out the change of the classification and/or
  ' the symbol to see what effect this has.
  maxclass = maxclass - 1
 count = count + 1
'---------------------------- END SCRIPT -----------------------------------
  1. Attach the script to a button on the View GUI.
    1. Compile the script.
    2. Switch to the Project window.
    3. Select Customize from the Project menu.
    4. On the Customize dialog box, click the Type drop-down arrow and click View.
    5. Select Buttons under Category.
    6. Click the New button.
    7. Double-click the Click property in the Customize dialog box.
    8. Type the name of the script in the Script Manager and click Select.
    9. Close the Customize dialog box.

For more information, see "Customize dialog box" in ArcView Help.