HOW TO
You can store and retrieve information about multiple items using a dictionary. The script in this document demonstrates how to create a legend classification using a dictionary.
Code:
'-- Unique Value Legend Example
'-- This script creates a Unique Values Legend and symbolizes
'-- the classes from sample data province.shp
theView = av.GetProject.FindDoc("View1")
theTheme = theView.GetActiveThemes.Get(0)
theLegend = theTheme.GetLegend
'-- First Set the LegendType
theLegend.SetLegendType(#LEGEND_TYPE_UNIQUE)
'-- Make the Unique Legend
theLegend.Unique(theTheme,"name")
thecolorpanel = av.getsymbolwin.getpalette.getlist(#PALETTE_LIST_COLOR)
thedictionary = dictionary.make(40)
theDictionary.add("Quebec",thecolorpanel.get(7))
theDictionary.add("Northwest Territories",thecolorpanel.get(9))
theDictionary.add("Nova Scotia",thecolorpanel.get(11))
theDictionary.add("Saskatchewan",thecolorpanel.get(13))
theDictionary.add("Alberta",thecolorpanel.get(15))
theDictionary.add("Newfoundland and Labrador",thecolorpanel.get(17))
theDictionary.add("British Columbia",thecolorpanel.get(19))
theDictionary.add("New Brunswick",thecolorpanel.get(21))
theDictionary.add("Prince Edward Island",thecolorpanel.get(23))
theDictionary.add("Yukon Territory",thecolorpanel.get(25))
theDictionary.add("Manitoba",thecolorpanel.get(27))
theDictionary.add("Ontario",thecolorpanel.get(39))
theDictionary.add("No data",thecolorpanel.get(41))
'-- Change the TOC and redraw the theme.
theClasses = thelegend.getclassifications
classclone = theclasses.clone
theSymbols = thelegend.getsymbols
classcount = {}
cont = theClasses.count - 2
for each i in classclone
theLabel = i.getlabel
if (thedictionary.get(thelabel) <> nil) then
if (thelabel <> "no data") then
classcount.insert(i.clone)
theclasses.remove(cont)
end
else
theclasses.remove(cont)
theSymbols.remove(cont)
end
cont = cont - 1
end
cont = 0
for each i in classcount
theLabel = i.getlabel
if (thelabel <>"no data") then
if (thedictionary.get(thelabel) <> nil) then
theClasses.insert(i)
theSymbols.get(cont).setcolor(thedictionary.get(thelabel))
cont = cont + 1
end
end
end
theTheme.UpdateLegend
'-- End of Script
Note:
The results of this Avenue code can be reproduce by Clicking the Load and Save legend button on the Legend editor.
Article ID:000002469
Get help from ArcGIS experts
Download the Esri Support App