<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic User parameters in script not recognized in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/254998#M2707</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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).&amp;nbsp; It work fine in model builder, but when I exported it as a Py script, it does not work right.&amp;nbsp; When run, it ignores the user/parameter input, and uses the default values I added when making the model.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How do I get it to accept the user entries? Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Section = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Section = "\"SECTION\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Township = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Township = "\"TOWNSHIP\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Range = arcpy.GetParameterAsText(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Range = "\"RANGE\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Range_dir = arcpy.GetParameterAsText(3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Range_dir = "\"RANGE_DIR\" = 'E'" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS = "PLSS"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__1_ = Section&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__2_ = Township&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__4_ = Range&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__5_ = Range_dir&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", Section)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Township)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Town_dir&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP_D\" = 'S'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (4)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (5)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range_dir)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Sep 2010 12:59:50 GMT</pubDate>
    <dc:creator>MikeHouts</dc:creator>
    <dc:date>2010-09-14T12:59:50Z</dc:date>
    <item>
      <title>User parameters in script not recognized</title>
      <link>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/254998#M2707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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).&amp;nbsp; It work fine in model builder, but when I exported it as a Py script, it does not work right.&amp;nbsp; When run, it ignores the user/parameter input, and uses the default values I added when making the model.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How do I get it to accept the user entries? Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Section = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Section = "\"SECTION\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Township = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Township = "\"TOWNSHIP\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Range = arcpy.GetParameterAsText(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Range = "\"RANGE\" = 5" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Range_dir = arcpy.GetParameterAsText(3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Range_dir = "\"RANGE_DIR\" = 'E'" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS = "PLSS"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__1_ = Section&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__2_ = Township&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__4_ = Range&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS__5_ = Range_dir&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", Section)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Township)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Town_dir&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", "\"TOWNSHIP_D\" = 'S'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (4)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Select Layer By Attribute (5)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "SUBSET_SELECTION", Range_dir)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Sep 2010 12:59:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/254998#M2707</guid>
      <dc:creator>MikeHouts</dc:creator>
      <dc:date>2010-09-14T12:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: User parameters in script not recognized</title>
      <link>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/254999#M2708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No solution yet, but Im updating my original post with a simplified version.&amp;nbsp; If I run the below model as is, it wont run and I get the folowing error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Running script selecttestvariable...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000358: Invalid expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (selecttestvariable).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But, if comment out the next to last line and activate the last line (changing from user defined parameter to hard coded select section 1) it runs fine. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a problem with my "GetParameterAsText" or could it be in the script properties in the toolbox (currently parameters defined as data type = long, required, input... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import arcpy module&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "G:/temp/"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SelCondition = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PLSS = "PLSS"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#### Use the SelectLayerByAttribute tool to select a Section&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", SelCondition)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = 1")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Sep 2010 18:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/254999#M2708</guid>
      <dc:creator>MikeHouts</dc:creator>
      <dc:date>2010-09-15T18:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: User parameters in script not recognized</title>
      <link>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/255000#M2709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Got it figured out.&amp;nbsp; I had to combine the attribute name with the variable parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Use the SelectLayerByAttribute tool to select a Section&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = "+SelCondition)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# the above is the variable version of this&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.SelectLayerByAttribute_management(PLSS, "NEW_SELECTION", "\"SECTION\" = 1")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Sep 2010 19:18:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/user-parameters-in-script-not-recognized/m-p/255000#M2709</guid>
      <dc:creator>MikeHouts</dc:creator>
      <dc:date>2010-09-15T19:18:53Z</dc:date>
    </item>
  </channel>
</rss>

