English

How To: Create a classified legend with Avenue [SCRIPT]

Procedure

This document shows how to create a classified legend using Avenue.

Answer:

The script below does the following:

1. Creates a new view
2. Creates a theme containing the USA states information
3. Classifies the states based upon area
4. Creates a legend and assigns colors to it based upon the area
classification

'--- Script

'--- Get project
theProject = av.GetProject

'--- Create and open view
theView = av.getactivedoc

'--- Create and add state theme to view
theSource = SrcName.Make("c:\esri\esridata\usa\states.shp")
theTheme = Theme.Make(theSource)
theView.AddTheme(theTheme)
theTheme.SetVisible(True)

'--- Create classification list
a_class = Classification.Make(0, 49999)
b_class = Classification.Make(50000, 99999)
c_class = Classification.Make(100000, 576595)
theClassList = {a_class, b_class, c_class}

'--- Set themes legend classification to 3 classes
theLegend = theTheme.GetLegend
theLegend.SetLegendType(#LEGEND_TYPE_COLOR)
theLegend.Interval(theTheme, "Area", 3)

'--- Modify classifications to desired intervals defined above
currentClassifications = theLegend.GetClassifications
cnt = 0
for each i in theClassList
currentClassifications.Set(cnt, theClassList.Get(cnt))
cnt = cnt + 1
end

'--- Set legend fill pattern and color
theLegend = theTheme.GetLegend
theSymList = theLegend.GetSymbols
theSymList.Get(0).SetColor(Color.GetRed)
theSymList.Get(1).SetColor(Color.GetGreen)
theSymList.Get(2).SetColor(Color.GetBlue)

'--- Redraw the view
theTheme.UpdateLegend
theView.Invalidate

'--- End of Script