How To: Emulate sort order buttons in the Legend Editor through Avenue
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.
- Open a new script window. A. Activate the Project window.
B. Click the Scripts icon.
C. Click New.
- 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 -----------------------------------
- Attach the script to a button on the View GUI. A. Compile the script.
B. Switch to the Project window.
C. Select Customize from the Project menu.
D. On the Customize dialog box, click the Type dropdown arrow and click View.
E. Select Buttons under Category.
F. Click the New button.
G. Double-click the Click property in the Customize dialog box.
H. Type the name of the script in the Script Manager and click Select.
I. Close the Customize dialog box.
For more information, see "Customize dialog box" in ArcView Help.