HOW TO

Randomly select features using Avenue

Last Published: April 25, 2020

Summary

The script in this article randomly selects features in a theme.

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:
    theView = av.GetActiveDoc
    theDisplay = theView.GetDisplay
    ThemeList = av.GetActiveDoc.GetActiveThemes
    if (ThemeList.Count <> 1) Then
    msgbox.Error("You must have one and only one active theme",
    "Select Random Sample is aborting")
    exit
    end
    theTheme = ThemeList.Get(0)
    theFtab = theTheme.GetFtab
    theBitMap = theFtab.GetSelection
    theBitMap.ClearAll
    TotalRecs = theFtab.GetNumRecords
    numselect = MsgBox.Input("Enter the Number of Total Population:",
    "Select Random Sample","1")

    if ((numselect = NIL) or (numselect.IsNumber.Not)) then exit end
    if((numselect.AsNumber > totalrecs) or (numselect.AsNumber < 1)) then
    Msgbox.Error("You must enter a number between 0 and"
    ++totalrecs.asstring ,"Select Random Sample is aborting")
    exit
    end
    selectnumber = numselect.asnumber
    for each n in 1..selectnumber
    newnumber = Number.MakeRandom ( 0, totalrecs)
    tf = thebitmap.get(newnumber)
    while (tf.asstring = "true")
    newnumber = number.makerandom(0, totalrecs)
    tf = thebitmap.get(newnumber)
    end
    if (tf.asstring = "false") then
    theBitMap.Set(newnumber)
    else
    end
    end

    theDisplay.Invalidate(True)

  3. Attach the script to a button on the View GUI.

    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.

  4. Open the view and make one theme active.
  5. Click the new button.

Article ID:000004219

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