Hi,
I created a short model to update one field based on another in a SQl geodatabase using modelbuilder, exported it to python, however it only works in pyscripter not in python.
It seems Calculate field cannot use VB expressions in 64-bit ArcGIS products. I'm not sure of python so can anyone tell me how to change this vb code into python in the Code Block of Calculate Field
If IsNull ([ColumnA]) then
[ColumnA] = [ColumnB]
End If
ColumnA is a date field so if it is Null then update it with ColumnB (text field).
Many thanks
Rachel
You would need to put it in a Python definition function:
Thank you, this worked and the model runs with the python in the codeblock, however when I export it to python and run it, it's saying Error 000732: Input Table x does not exist or is not supported. Failed to execute (calculate Field).
This is what my python script looks like
# Import arcpy module import arcpy # Local variables: Seizures_DBO_Seizures = "Database Servers\\servername_SQLEXPRESS.gds\\Seizures (VERSION:dbo.DEFAULT)\\Seizures.DBO.Seizures" Seizures_DBO_Seizures2 = Seizures_DBO_Seizures # Process: Calculate Field arcpy.CalculateField_management(Seizures_DBO_Seizures, "Date_Seized", "setField( !Date_Seized!, !DateSeized!)", "PYTHON_9.3", "def setField( val1, val2 ):\\n if val1 is None:\\n return val2\\n else:\\n return val1")
The Date_Seized was ColumnA
And DateSeized was ColumnB.
Would it be something to do with the blackslashes is doesn't like?
Many thanks
Rachel
Try setting your input parameters as variables before running the Calculate Field step as on this example page: Calculate Field—Data Management toolbox | ArcGIS for Desktop (search for the Calculate ranges example)
I changed the filepath to
r"C:\Users\mynamet\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\databasename\datasetname
and that seems to have done the trick.
Many thanks for your help
Rachel