<?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 Re: ArcPy script in toolbox - what do I do about optional parameters? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547477#M42746</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the code is fine. I tested it, and for me it worked:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy value = arcpy.GetParameterAsText(0) if value == "#" or value == "":&amp;nbsp; &amp;nbsp; value = None if value: &amp;nbsp; arcpy.SelectLayerByAttribute_management("dachflaechen","NEW_SELECTION", "\"OBJECTID\" = "+value) else: &amp;nbsp; arcpy.AddError("no value")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Aug 2012 10:49:07 GMT</pubDate>
    <dc:creator>JochenManegold</dc:creator>
    <dc:date>2012-08-21T10:49:07Z</dc:date>
    <item>
      <title>ArcPy script in toolbox - what do I do about optional parameters?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547476#M42745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I made my first Python tool this week, a Search by Attribute tool to search our cadastre. When I have required parameters it works beautifully. As soon as I make the parameters optional, it doesn't return any results (even if I complete all the fields). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I doing wrong? I added the 'if' line after reading another thread about optional parameters, but it doesn't make any difference with this problem. Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#define user parameter for road name, and locality&amp;nbsp; SelCondition = arcpy.GetParameterAsText(0) if (not SelCondition) or (SelCondition == "#") or (len(SelCondition.strip()) == 0):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelCondition = ""&amp;nbsp;&amp;nbsp; LocalityName = arcpy.GetParameterAsText(1) if (not LocalityName) or (LocalityName == "#") or (len(LocalityName.strip()) == 0):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LocalityName = ""&amp;nbsp;&amp;nbsp; # select cadastral lots on road name and locality, and lot no arcpy.SelectLayerByAttribute_management("Cadastre","NEW_SELECTION", "\"ROAD_NAME\" = "+SelCondition)&amp;nbsp; arcpy.SelectLayerByAttribute_management("Cadastre","SUBSET_SELECTION", "\"LOCALITY\" = "+LocalityName) &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2012 06:42:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547476#M42745</guid>
      <dc:creator>RosieBell</dc:creator>
      <dc:date>2012-08-21T06:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script in toolbox - what do I do about optional parameters?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547477#M42746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the code is fine. I tested it, and for me it worked:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy value = arcpy.GetParameterAsText(0) if value == "#" or value == "":&amp;nbsp; &amp;nbsp; value = None if value: &amp;nbsp; arcpy.SelectLayerByAttribute_management("dachflaechen","NEW_SELECTION", "\"OBJECTID\" = "+value) else: &amp;nbsp; arcpy.AddError("no value")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2012 10:49:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547477#M42746</guid>
      <dc:creator>JochenManegold</dc:creator>
      <dc:date>2012-08-21T10:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script in toolbox - what do I do about optional parameters?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547478#M42747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#define user parameter for road name, and locality&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SelCondition = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (not SelCondition) or (SelCondition == "#") or (len(SelCondition.strip()) == 0):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SelCondition = "" &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;LocalityName = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if (not LocalityName) or (LocalityName == "#") or (len(LocalityName.strip()) == 0):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LocalityName = "" &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# select cadastral lots on road name and locality, and lot no&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;roadQuery = " UPPER(\"{0}\") = UPPER('{1}') ".format(ROAD_NAME, string.upper(SelCondition))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("Cadastre","NEW_SELECTION", roadQuery)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;localityQuery = " UPPER(\"{0}\") = UPPER('{1}') ".format(LOCALITY, string.upper(LocalityName))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("Cadastre","NEW_SELECTION", localityQuery)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Aug 2012 12:20:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547478#M42747</guid>
      <dc:creator>KenCarrier</dc:creator>
      <dc:date>2012-08-21T12:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script in toolbox - what do I do about optional parameters?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547479#M42748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry for the slow reply. I tried both solutions shortly after they were posted, but couldn't get either of them to work. I tried again jm's solution again today and it did the job, many thanks. carrierkh, no doubt it was my inexperience that was the problem, so thankyou for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Sep 2012 06:12:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-script-in-toolbox-what-do-i-do-about/m-p/547479#M42748</guid>
      <dc:creator>RosieBell</dc:creator>
      <dc:date>2012-09-28T06:12:39Z</dc:date>
    </item>
  </channel>
</rss>

