HOW TO

Set a specific symbol for the feature theme

Last Published: April 25, 2020

Summary

The sample scripts in this article demonstrate how to set symbols for a theme.

Procedure



  • Simple legend for point and line themes.

    Code:
    '-- Create a new theme from a feature source:
    theView = av.GetProject.FindDoc("View1")

    '-- This line has to be changed for line themes. Use arc instead
    '-- of point for feature type. You will need to make changes
    '-- to the path where your data resides.

    theTheme = Theme.Make("c:\esri\esridata\usa\cities.shp".AsSrcName)
    theTheme.SetName("Calif Cities")
    theView.AddTheme(theTheme)
    theTheme.SetVisible(true)
    theTheme.SetActive(true)

    theLegend = theTheme.GetLegend
    NewLegend = theLegend.Clone

    '-- Refer the symbol palette for the number to be used with Get().
    '-- For line themes use #PALETTE_LIST_PEN instead of #PALETTE_LIST_MARKER.

    CurrSymbol = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_MARKER).Get(1)
    NewSymbol = Symbol.Make(#SYMBOL_MARKER)
    NewSymbol.Copy(CurrSymbol)
    NewSymbol.SetColor(Color.GetRed)
    NewSymbol.SetSize(6)
    NewLegend.GetSymbols.Set(0, NewSymbol)

    '-- Refresh the theme without refreshing other themes in the view.
    theTheme.SetLegend(NewLegend)
    theTheme.InvalidateLegend
    theTheme.UpdateLegend

  • Sample legend for polygon themes.

    Code:
    '-- Create a new theme from a feature source:
    theView = av.GetProject.FindDoc("View1")

    '-- You will need to make changes to the path where your data resides.

    theTheme = Theme.Make("c:\esri\esridata\usa\counties.shp".AsSrcName)
    theTheme.SetName("USA Counties")
    theView.AddTheme(theTheme)
    theTheme.SetVisible(true)
    theTheme.SetActive(true)

    theLegend = theTheme.GetLegend
    '-- Modified lines.
    '------------------
    '-- This returns a COLOR object, not a SYMBOL; thus, create a
    '-- new symbol and set its color using this returned object.
    NewCol = av.GetSymbolWin.GetPalette.GetList(#PALETTE_LIST_COLOR).Get(9)
    NewSymbol = Symbol.Make(#SYMBOL_FILL)
    NewSymbol.SetColor(NewCol)
    '------------------

    NewLegend = theLegend.GetSymbols.Set(0, NewSymbol)

    '-- Refresh the theme without refreshing other themes in the view.
    theTheme.InvalidateLegend

  • Graduated legend classification.

    Code:
    '-- Sample script to manipulate the Legend of a theme
    '-- and its classifications (Values and Labels)
    '-- The example uses a legend with three classifications.

    '-- Gets the view
    theView = av.GetProject.FindDoc("View1")

    '-- Get the theme. Use sample data in AVDATA. If other themes are
    '-- used, the values for classification should be changed.
    theTheme = theView.FindTheme("States")

    '-- Get legend and corresponding classifications.
    theLegend = theTheme.GetLegend
    theClasses = theLegend.GetClassifications

    '-- Define the shade symbol for all the unselected countries.
    b = Symbol.Make(#SYMBOL_FILL)
    b.SetColor(Color.GetRed)
    b.SetOlColor(Color.GetBlack)

    '-- Update the legend with this symbol. This symbol is added as
    '-- the first element in the legend's symbol list.
    theLegend.GetSymbols.Set(0,b)

    '-- Define the shade symbol for the selected country.
    c = Symbol.Make(#SYMBOL_FILL)
    c.SetColor(Color.GetGreen)
    c.SetOlColor(Color.GetBlack)

    '-- Update the legend with this symbol. This symbol is added
    '-- as the second element in the legend's symbol list.
    '-- Symbol b is again added to the symbol list as the third element.

    theLegend.GetSymbols.Set(1,c)
    theLegend.GetSymbols.Set(2,b)

    '-- Manipulate the classification values and labels
    i = theClasses.Get(0)
    i.SetMinimum(1)
    i.SetMaximum(39)

    i.SetLabel("1 - 39")

    i = theClasses.Get(1)
    i.setMinimum(40)
    i.SetMaximum(40)
    i.SetLabel("40")

    i = theClasses.Get(2)
    i.SetMinimum(41)
    i.SetMaximum(51)
    i.SetLabel("41-51")

    '-- Update the theme with the new shades.
    theTheme.UpdateLegend
    theview.invalidate

  • To use these scripts:

    1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.



    2. Copy a script into the new window.

    3. Change the paths in the script to match the data on your machine.

    4. Click the Compile button.
    [O-Image] Script compile button
    5. Click the Run button.
    [O-Image] Run compiled script button
    Repeat these steps for the other scripts.

Article ID:000003933

Software:
  • Legacy Products

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options