how to set a variable from a list

625
2
Jump to solution
04-13-2011 07:54 AM
by Anonymous User
Not applicable
Original User: frankv3

i want to make a model that the user can select a choice from a list in the dialog and that choice will be passed as a variable to a python script
the model has a list of choices that show up as parameters but the model runs for all of them and not just the one selected
also is there a way to use a table or file to create the selection list for a variable in model builder instead of typing each choice itn the add variable box?
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor
I could be wrong, and I'd be interested to know a model builder solution, but the only way I can think of to get a selection from a list is with ArcObjects. Once you have that selection, you could call the rest of your python script.

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: frankv3

could anyone just point me in the right direction on this?

this is the code that the selection of the list would get, it runs fine with the user typing in the selection

## Import standard modules
import sys, os

## Set the product code
import arcinfo

## Import arcpy module and environment module
import arcpy
import arcpy.mapping
from arcpy import env

## Sets the MXD file to the current ArcMap MXD, if run out of ArcMap use the full path to the MXD file
IMXD = arcpy.mapping.MapDocument("CURRENT")

## Set Data Frames for the layer to select from
MDF = arcpy.mapping.ListDataFrames(IMXD, "Main Map")[0]

## Set the Index layers
ILyr = arcpy.mapping.ListLayers(IMXD,"PLSS")[0]

## Set the Section, Township and Range
STR = arcpy.GetParameterAsText(0)
# STR = '5-15-33'

## Create the SQL Query for the sheet number
SheetQry = r"SecTwnRng = '%s'"%(STR)

## Select the Aerial
try:
   arcpy.SelectLayerByAttribute_management(ILyr, "NEW_SELECTION", SheetQry)
   Num = str(arcpy.GetCount_management(ILyr))
   if Num == "0":
       arcpy.AddMessage("!! NO CORRESPONDING PLSS AREA EXISTS FOR THIS REQUEST !!")
   else:
       ## Get Extent of Selected Sheet
       IExt = ILyr.getSelectedExtent()

       ## Pan to selected extent
       MDF.panToExtent(IExt)

       # Get the seperated STR text
       SECTWNRNG = STR.split("-")
       SEC = SECTWNRNG[0]
       TWN = SECTWNRNG[1]
       RNG = SECTWNRNG[2]

       ## Set the S-T-R Text
       for SheetNum in arcpy.mapping.ListLayoutElements(IMXD, "TEXT_ELEMENT"):
           if SheetNum.text == "SEC         TWN         RNG":
               SheetNum.text = r"%s           %s           %s"%(SEC, TWN, RNG)
       
       ## Refresh data farame
       arcpy.RefreshActiveView
       arcpy.AddMessage("Please refresh the map on completion")
except:
   arcpy.GetMessages()
0 Kudos
DarrenWiens2
MVP Honored Contributor
I could be wrong, and I'd be interested to know a model builder solution, but the only way I can think of to get a selection from a list is with ArcObjects. Once you have that selection, you could call the rest of your python script.
0 Kudos