HOW TO
The script in this article randomly selects features in a theme.
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)
Article ID:000004219
Get help from ArcGIS experts
Download the Esri Support App