I am playing around with trying to pass the AreaFieldName of a polygon feature class into the CalculateField_management function. No matter which way I attempt to do this, it returns:
arcgisscripting.ExecuteError: ERROR 000539: Invalid field %areaFieldName%
Failed to execute (CalculateField).
I've done something like this:
That doesn't work. I tried to convert the AreaFieldName to string:
Same result.
I thought I'd shortcut my troubleshotting by setting up the same scenario with the same data in model builder and export to script to see if my syntax was right:
That works. I'm at a loss. Can anyone suggest why this is failing?
Quote:
arcgisscripting.ExecuteError: ERROR 000539: Invalid field %areaFieldName%
Failed to execute (CalculateField).
Code:
areaFieldName = arcpy.Describe(FC).AreaFieldName
arcpy.AddField_management(FC, "AREA_OF_OVERLAP_HA", "DOUBLE", "", "", "", "AREA OF OVERLAP (HA)")
arcpy.CalculateField_management(FC, "AREA_OF_OVERLAP_HA", "round(!%areaFieldName%! /10000,2)", "PYTHON")
Code:
areaFieldName = str(arcpy.Describe(FC).AreaFieldName)
I thought I'd shortcut my troubleshotting by setting up the same scenario with the same data in model builder and export to script to see if my syntax was right:
Code:
# Local variables:
Field = "GEOMETRY_Area"
Coal_Bed = "W:\\Test_FeatureClasses.gdb\\Test_FC"
# Process: Calculate Field
arcpy.CalculateField_management(Coal_Bed, "AREA_OF_OVERLAP_HA", "round(!%Field%! /10000,2)", "PYTHON", "")