<?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: Working with optional parameters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535556#M41958</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much Xander!!! It works!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy new year to you &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Jan 2015 14:44:22 GMT</pubDate>
    <dc:creator>Sheri_AnneSantos</dc:creator>
    <dc:date>2015-01-06T14:44:22Z</dc:date>
    <item>
      <title>Working with optional parameters</title>
      <link>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535554#M41956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi smart people!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created a script to automate our workflow at work but have been having difficulty with my optional parameter. I've googled every possible help i could get with this but nothing so far...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see below the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Import all necessary modules&lt;BR /&gt;import os, sys, arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;import getpass&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Define all objects to be used&lt;BR /&gt;sde_conn = "S:/Projects/Oilsands/FortHills/OS0101_Fort_Hills_MPG/010_FH_GDA/002-GDA_LOG/My_ArcSDE_Conn.sde"&lt;BR /&gt;outpath = sde_conn + "/"&lt;BR /&gt;gdaFC = "FORTHILLS.GDA_PERMIT_BOUNDARY_A"&lt;BR /&gt;arcpy.AddMessage("SDE Connection Successful")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Prompt for user parameters&lt;BR /&gt;table = arcpy.GetParameterAsText(0)&lt;BR /&gt;field = arcpy.GetParameterAsText(1)&lt;BR /&gt;gdanum = arcpy.GetParameterAsText(2)&lt;BR /&gt;extstart = arcpy.GetParameter(3)&lt;BR /&gt;extend = arcpy.GetParameter(4)&lt;BR /&gt;extdue = arcpy.GetParameter(5)&lt;BR /&gt;&lt;SPAN style="color: #e23d39;"&gt;asbsubmit = arcpy.GetParameter(6) # Optional Parameter&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;arcpy.SetParameter(3, gdanum)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Specify selection&lt;BR /&gt;whereClause = '"GDA_NUMBER"' + " = '" + str(gdanum) + "'"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Updates information of gda feature class&lt;BR /&gt;try:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.UpdateCursor(outpath + gdaFC, whereClause)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_START_DATE", extstart)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_FINISH_DATE", extend)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_DUE_DATE", extdue)&lt;BR /&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("ASBUILT_SUBMIT_DATE", asbsubmit) # Script should skip this if no value entered&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("STATUS", "E")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("INTERNAL_ROW_CHANGED_DATE", time.strftime("%x %X", time.localtime()))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("INTERNAL_ROW_CHANGED_BY", getpass.getuser().upper())&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor, row&lt;/P&gt;&lt;P&gt;except:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages(1)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;arcpy.AddMessage("GDA has been extended")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Jan 2015 19:41:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535554#M41956</guid>
      <dc:creator>Sheri_AnneSantos</dc:creator>
      <dc:date>2015-01-03T19:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Working with optional parameters</title>
      <link>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535555#M41957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When a parameter is not set, this is normally replaced by a "#" sign. I did a small test and reading the optional parameter when it is supposed to be an object ended in a "&lt;EM&gt;Object: Error in getting parameter as text&lt;/EM&gt;" error. So I placed it in a try except and assigned it to None when there is an error (presumably the parameter was not set).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess you could do something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import all necessary modules
import os, sys, arcpy
from arcpy import env
import getpass

# Define all objects to be used
sde_conn = "S:/Projects/Oilsands/FortHills/OS0101_Fort_Hills_MPG/010_FH_GDA/002-GDA_LOG/My_ArcSDE_Conn.sde"
gdaFC = "FORTHILLS.GDA_PERMIT_BOUNDARY_A"
fld_gdanum = "GDA_NUMBER"

# Prompt for user parameters
table = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
gdanum = arcpy.GetParameterAsText(2)
extstart = arcpy.GetParameter(3)
extend = arcpy.GetParameter(4)
extdue = arcpy.GetParameter(5)
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; asbsubmit = arcpy.GetParameter(6) # Optional Parameter
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; asbsubmit = None
##arcpy.SetParameter(3, gdanum)

# Specify selection
fc = os.path.join(sde_conn, gdaFC)
whereClause = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_gdanum), gdanum)

# Updates information of gda feature class
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.UpdateCursor(fc, whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_START_DATE", extstart)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_FINISH_DATE", extend)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("EXTENSION_DUE_DATE", extdue)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if asbsubmit != None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("ASBUILT_SUBMIT_DATE", asbsubmit) # Script should skip this if no value entered
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("STATUS", "E")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("INTERNAL_ROW_CHANGED_DATE", time.strftime("%x %X", time.localtime()))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("INTERNAL_ROW_CHANGED_BY", getpass.getuser().upper())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor, row
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages(1)

arcpy.AddMessage("GDA has been extended")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I switched line 22 off. Not sure why you want to set the value of the parameter extstart (3) to contain the value contained in gdanum...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535555#M41957</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T23:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Working with optional parameters</title>
      <link>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535556#M41958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much Xander!!! It works!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Happy new year to you &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 14:44:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535556#M41958</guid>
      <dc:creator>Sheri_AnneSantos</dc:creator>
      <dc:date>2015-01-06T14:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Working with optional parameters</title>
      <link>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535557#M41959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm glad it works. Happy New Year to you too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jan 2015 22:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/working-with-optional-parameters/m-p/535557#M41959</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-01-06T22:51:41Z</dc:date>
    </item>
  </channel>
</rss>

