How To: Emulate sort order buttons in the Legend Editor through Avenue
Note: 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.
- Open a new script window.
- Activate the Project window.
- Click the Scripts icon.
- 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. ' thelegend.getclassifications.set(count,clonedlist.get(maxclass)) thelegend.getsymbols.set(count,clonedlist2.get(maxclass)) maxclass = maxclass - 1 end count = count + 1 end thetheme.updatelegend '---------------------------- END SCRIPT -----------------------------------
- Attach the script to a button on the View GUI.
- Compile the script.
- Switch to the Project window.
- Select Customize from the Project menu.
- On the Customize dialog box, click the Type drop-down arrow and click View.
- Select Buttons under Category.
- Click the New button.
- Double-click the Click property in the Customize dialog box.
- Type the name of the script in the Script Manager and click Select.
- Close the Customize dialog box.
For more information, see "Customize dialog box" in ArcView Help.