Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Passing AreaFieldName as a variable into CalculateField Failing

$
0
0
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:

Quote:

arcgisscripting.ExecuteError: ERROR 000539: Invalid field %areaFieldName%
Failed to execute (CalculateField).
I've done something like this:

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

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

Code:

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:

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

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

Viewing all articles
Browse latest Browse all 2485

Trending Articles