I have been having a hard time trying to get my simple model to work thinking that it was something to do with my naive python programming, but have finally come across the reason. Modelbuilder refuses to calculate my field values after an optional field has no value assigned to it.
In the following code I assign 3 parameters: the Featureclass to parameter (0), and two text fields. All except the first field is optional. If I however leave parameter (1) empty in the modelbuilder dialog, modelbuilder just exits without a message and doesn´t fill in the values for parameter (2). I have been struggling with this all day thinking it was a formatting problem with my date fields, but it seems to lie with this strange behaviour.
Is this a bug or does this have some logic?
import sysimport arcpyfrom arcpy import envimport datetime# allow overwriteOutputenv.overwriteOutput = True# for Scriptfc = arcpy.GetParameterAsText(0)PlanzNr = arcpy.GetParameterAsText(1)PlanzKat = arcpy.GetParameterAsText(2)try: arcpy.CalculateField_management(fc,"PlanzNr", PlanzNr,"PYTHON") arcpy.CalculateField_management(fc,"PlanzKat",PlanzKat,"PYTHON") except Exception, e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message
أكثر...
In the following code I assign 3 parameters: the Featureclass to parameter (0), and two text fields. All except the first field is optional. If I however leave parameter (1) empty in the modelbuilder dialog, modelbuilder just exits without a message and doesn´t fill in the values for parameter (2). I have been struggling with this all day thinking it was a formatting problem with my date fields, but it seems to lie with this strange behaviour.
Is this a bug or does this have some logic?
import sysimport arcpyfrom arcpy import envimport datetime# allow overwriteOutputenv.overwriteOutput = True# for Scriptfc = arcpy.GetParameterAsText(0)PlanzNr = arcpy.GetParameterAsText(1)PlanzKat = arcpy.GetParameterAsText(2)try: arcpy.CalculateField_management(fc,"PlanzNr", PlanzNr,"PYTHON") arcpy.CalculateField_management(fc,"PlanzKat",PlanzKat,"PYTHON") except Exception, e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message
أكثر...