Is This Content Helpful?
We're glad to know this article was helpful.
You can use the following Avenue script to limit the classes displayed in a legend to only those that correspond to features within the current extent of the view.
'-- This script temporarily limits each theme to just the records
'-- in the display's extent and uses the built-in capability of a
'-- legend to return class counts to determine which classes
'-- it can dispense with. It is a general approach that
'-- does not need to worry about the details of each legend.
'-- Obtain the view's extent. It will be used to select the
'-- features for classification.
if (theView.Is(View).Not) then return NIL end
theExtent=theView.GetDisplay.ReturnExtent '-- Will select in the visible extents
'-- Process each active theme, if any.
sLog = "" ' Records what happens
for each theTheme in theView.GetActiveThemes
if (theTheme.Is(FTheme) and theTheme.CanSelect and
'-- Select visible features.
'-- Limit the theme to the selected features.
'-- Remove unused classes from the legend.
lstCounts = theTheme.ReturnClassCounts
lstClassifications = theTheme.GetLegend.GetClassifications
lstSymbols = theTheme.GetLegend.GetSymbols
n = 0 ' Counts the number of classes removed.
for each i in lstClassifications.Count-2..0 by -1 ' Skip the NoData class
if (lstCounts.Get(i) = 0) then
n = n+1
theTheme.UpdateLegend ' Cause the legend to redraw in the TOC
'-- Log the changes.
if (n = 1) then sClass = "class" else sClass = "classes" end
sLog = sLog + NL + "[" + theTheme.GetName + "]: " +
n.AsString ++ sClass ++ "removed."
'-- Restore the original definition and selection.
else '-- This is an image or grid theme, most likely.
sLog = sLog + NL + "[" + theTheme.GetName + "] could not be modified."
'-- Summarize results.
if (sLog <> "") then
MsgBox.Report("Summary of changes made to legends:" + NL + sLog, Script.The.GetName)
'-- End of Script