HOW TO
The sample Avenue script in this article sorts the view's Table of Contents (TOC) alphabetically by theme name.
Code:
'-- Sort order of TOC by theme name
aView = av.GetActiveDoc '-- Get the view
theThemes = aView.GetThemes '-- Get the themes
if (theThemes = NIL) then
exit
end
theThemesName = {}
'-- Create list of theme names as string
for each thm in theThemes
theThemesName.Add(thm.GetName)
end
'-- Sort theme name list according to user prefered order
order = MsgBox.ChoiceAsString({"Ascending","Descending"},"Choose order for themes in TOC","TOC ORDER")
if(order = nil) then
exit
else if (order = "Descending") then
theThemesName.Sort(True)
else
theThemesName.Sort(False)
end
end
'-- Delete sorted theme and add to top of view
for each thm in theThemesName
theTheme = aView.FindTheme(thm)
aView.DeleteTheme(theTheme)
aView.AddTheme(theTheme)
end
'-- Refresh TOC and view
aView.InvalidateTOC(nil)
aView.Invalidate
Get help from ArcGIS experts
Download the Esri Support App