HOW TO

Modify the symbols in a theme legend [SCRIPT]

Last Published: April 25, 2020

Procedure

How to modify the symbols in a theme legend.

Answer:

The script below you how to modify the legend of a theme.

'--- EXAMPLE FOR SETTING LEGEND WITH AVENUE CODE
'--- This script uses sample data from Canada, with the theme set
'--- to region.prov classified on names, to adjust the fill pattern
'--- of Manitoba to a hard wired fill pattern. Given a selected
'--- symbol, this could also be applied to a simple legend as well,
'--- any selected them a given color or symbol.

theTheme = av.GetProject.FindDoc("View1").GetThemes.Get(0)

'--- Get the lists for each type
'--- Use only one of these examples, comment out the others
fillList = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_FILL)
colorList = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_COLOR)
penList = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_PEN)
markerList = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_MARKER)

'--- Get the legend
theLegend = theTheme.GetLegend

'--- Get the classification list
theclassificationslist = thelegend.getclassifications

'--- Get the symbols
theSymbollist = theLegend.GetSymbols

'--- Get some defaults from the lists
theSelectedColor = colorList.Get(0) ' not used - example
theSelectedSymbol = markerlist.get(19) ' not used - example
theSelectedFill = fillList.get(5)

'--- Extract the number of symbols, hence the classifications
theNumberOfSymbolsInTheTheme = theSymbolList.Count

'--- Use (uncomment) the loop below to change all elements in a theme
'--- classification, remember to uncomment the end statement as well
'--- Example for changing one element in a theme below
'-for each i in (0..(theNumberOfSymbolsInTheTheme - 1)) 'Adjust for start of 0

'-start the next loop and search for the specific classification
i=0
for each theelement in theclassificationslist
'--- Check to see if the class is the one we want to change
if (theelement.returnrangestring = "Manitoba") then
theSymbolList.Set(i,theSelectedFill)
'--- Debug code to test below
'-msgbox.info(i.asstring,theelement.returnrangestring)
else
i = i + 1
end

end
'-end '--- End of the optional loop

theTheme.InvalidateLegend
theTheme.UpdateLegend

'--- End of Script

Article ID:000001491

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic