mhouts

User parameters in script not recognized

Discussion created by mhouts on Sep 14, 2010
Latest reply on Sep 15, 2010 by mhouts
I created a select by attributes process in model builder where the selection criteria were parameters entered by the user to select on a series of attributes to narrow down the selection to a single polygon (township, range, section).  It work fine in model builder, but when I exported it as a Py script, it does not work right.  When run, it ignores the user/parameter input, and uses the default values I added when making the model. 

How do I get it to accept the user entries? Thanks.
Here is the code:


# Import arcpy module
import arcpy

# Script arguments
Section = arcpy.GetParameterAsText(0)
Section = "\"SECTION\" = 5" # provide a default value if unspecified

Township = arcpy.GetParameterAsText(1)
Township = "\"TOWNSHIP\" = 5" # provide a default value if unspecified

Range = arcpy.GetParameterAsText(2)
Range = "\"RANGE\" = 5" # provide a default value if unspecified

Range_dir = arcpy.GetParameterAsText(3)
Range_dir = "\"RANGE_DIR\" = 'E'" # provide a default value if unspecified

# Local variables:
PLSS = "PLSS"
PLSS__1_ = Section
PLSS__2_ = Township
PLSS__4_ = Range
PLSS__5_ = Range_dir

# Process: Select Layer By Attribute
arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", Section)

# Process: Select Layer By Attribute (2)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Township)

# Process: Town_dir
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP_D\" = 'S'")

# Process: Select Layer By Attribute (4)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range)

# Process: Select Layer By Attribute (5)
arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range_dir)

Outcomes