AnsweredAssumed Answered

Passing AreaFieldName as a variable into CalculateField Failing

Question asked by BrokenLegMike on Apr 17, 2014
Latest reply on Apr 17, 2014 by BrokenLegMike
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:

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")

That doesn't work. I tried to convert the AreaFieldName to string:

areaFieldName = str(arcpy.Describe(FC).AreaFieldName)

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:

# 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", "")

That works. I'm at a loss. Can anyone suggest why this is failing?