AnsweredAssumed Answered

Working with optional parameters

Question asked by ssantos1082 on Jan 3, 2015
Latest reply on Jan 6, 2015 by xander_bakker


Hi smart people!!

 

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...

 

Please see below the script:

 

# 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"
outpath = sde_conn + "/"
gdaFC = "FORTHILLS.GDA_PERMIT_BOUNDARY_A"
arcpy.AddMessage("SDE Connection Successful")

 

# 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)
asbsubmit = arcpy.GetParameter(6) # Optional Parameter

arcpy.SetParameter(3, gdanum)

 

# Specify selection
whereClause = '"GDA_NUMBER"' + " = '" + str(gdanum) + "'"

 

# Updates information of gda feature class
try:
    cursor = arcpy.UpdateCursor(outpath + gdaFC, whereClause)
    for row in cursor:
        row.setValue("EXTENSION_START_DATE", extstart)
        row.setValue("EXTENSION_FINISH_DATE", extend)
        row.setValue("EXTENSION_DUE_DATE", extdue)
        row.setValue("ASBUILT_SUBMIT_DATE", asbsubmit) # Script should skip this if no value entered
        row.setValue("STATUS", "E")
        row.setValue("INTERNAL_ROW_CHANGED_DATE", time.strftime("%x %X", time.localtime()))
        row.setValue("INTERNAL_ROW_CHANGED_BY", getpass.getuser().upper())
        cursor.updateRow(row)

    del cursor, row

except:
    print arcpy.GetMessages(1)
                               
arcpy.AddMessage("GDA has been extended")

Outcomes