I want to allow users to enter a date as a parameter through a dialog window in a toolbox script.
I have obviously defined the field with a "Date" data type but something is wrong with the formatting.
arcpy.CalculateField_management(fc, "Date", "01.07.2015", "PYTHON", "")
If I enter "01.07.2015" directly in the FieldCalculator in ArcMap it works, but I can´t define it as a parameter in arcpy? What am I doing wrong?
import sys
import arcpy
from arcpy import env
# allow overwriteOutput
env.overwriteOutput = True
# for Script
FC = arcpy.GetParameterAsText(0)
Date = arcpy.GetParameterAsText(1)
try:
arcpy.CalculateField_management(fc, "Stand", Date, "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
This is in Modelbuilder. The code runs, but the field is not updated. If I take remove the modelbuilder parameters and enter them in the python script the error is:
import sys
import arcpy
from arcpy import env
# allow overwriteOutput
env.overwriteOutput = True
Date = "01.01.2001"
try:
arcpy.CalculateField_management(fc, "Stand", Date, "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
ERROR:
Line 18
ERROR 000539: : unexpected EOF while parsing (, line 1)
Fehler beim Ausführen von (CalculateField).
No comments:
Post a Comment