English

How To: Change the current symbol of a theme using Avenue

Summary

Provides Avenue code to change the current symbol of a theme. The theme must be classified by a single symbol.

Procedure

  1. Open a new script window.

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

  2. Copy the code into the new script window.

    Code:
    '--- Description: This script will change the current symbol in a single
    '--- active theme to a new symbol. The script will prompt for a symbol number.
    '--- This symbol number corresponds with the order of the symbol in the respective
    '--- symbol list of the Palette Manager. For example, the upper left symbol in the
    '--- Marker Palette will be symbol 0, the next symbol to the right will be 1, etc...

    '--- Requires: A single active theme that contains one classification in its legend.
    '--- Themes that contain multiple classifications will require additional coding.
    '--- This script also requires that a View be the active document.

    '--- Get the active theme and check the feature type

    aView=av.GetActiveDoc
    aThList=aView.GetActiveThemes
    if (aThList.Count > 1) then
    MsgBox.Error("There is more than 1 active theme!","")
    exit
    else
    aTheme=aThList.Get(0)
    end
    aSrc=aTheme.GetSrcName
    aSub=aSrc.GetSubName

    '--- Grab the Symbol Window and the appropriate symbol list for the theme

    aSw=av.GetSymbolWin
    aPal=aSw.GetPalette
    if (aSub="Point") then
    aSList=aPal.GetList(#PALETTE_LIST_MARKER)
    elseif (aSub="Arc") then
    aSList=aPal.GetList(#PALETTE_LIST_PEN)
    elseif (aSub="Polygon") then
    aSList=aPal.GetList(#PALETTE_LIST_FILL)
    end
    cnt=aSlist.Count

    '--- Prompt user for the number of the symbol to be used from the the symbol
    list
    '--- and provide some error checking.

    for each x in 1..10
    num=MsgBox.Input
    ("Please enter the number of the symbol to be used:", "Symbol input","")
    if (num=nil) then exit end
    n=num.AsNumber
    if (n=nil) then
    exit
    elseif ((n > cnt) or (n < 1)) then
    if (x=3) then
    MsgBox.Info("Ending Rountine!", "Invalid Inputs")
    exit
    end
    MsgBox.Info
    ("Please re-enter value.","Value exceeds numbers of symbols in the list")
    else
    Break
    end
    end

    '--- Now selects the new symbol from the symbol list and clones it. Also the
    legend
    '--- is selected so that the Current symbol being used can be retrieved.

    aCurSym=aSlist.Get(n-1)
    aSym=aCurSym.Clone 'Prevents symbols in legend from changing colors
    aLegend=aTheme.GetLegend
    theSymbols=aLegend.GetSymbols

    '--- Grab the current symbol and color used in the legend. This will be applied back
    '--- to the new symbol later, and prevents the the default color from being applied
    '--- back to the new symbol

    Current=theSymbols.Get(0)
    aCurColor=Current.GetColor

    '--- Replace the old with the new by removing the old symbol from the symbol
    list
    '--- andthen adding the new one

    theSymbols.RemoveObj(Current)
    aSym.SetColor(aCurColor)
    theSymbols.Add(aSym)
    aTheme.UpDateLegend

    '------ End Of Script

  3. Compile the script by clicking the compile button.
    [O-Image] Script compile button
  4. Run the script by clicking the run button.
    [O-Image] Run compiled script button