HOW TO

Sort the view's TOC alphabetically via Avenue

Last Published: April 25, 2020

Summary

The sample Avenue script in this article sorts the view's Table of Contents (TOC) alphabetically by theme name.

Procedure



  1. Open a new script window.

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

  2. Copy the following code into the new window.

    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

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

Article ID:000004577

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic