Skip to content

Instantly share code, notes, and snippets.

@ustroetz
Created November 6, 2013 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ustroetz/7340870 to your computer and use it in GitHub Desktop.
Save ustroetz/7340870 to your computer and use it in GitHub Desktop.
import arcpy
# Get the feature name to work with
in_featureclass = arcpy.GetParameterAsText(0)
# Set local variables
field_Name = "ACRES"
field_Type = "DOUBLE"
field_Precision = 10 # total number of digits stored
field_Scale = 8 # number of decimal places
fieldList = arcpy.ListFields(in_featureclass, field_Name)
fieldCount = len(fieldList)
if fieldCount == 1:
# field already exists
arcpy.CalculateField_management(in_featureclass, field_Name, '!SHAPE.area@ACRES!', "PYTHON_9.3")
else:
#field doesn't exist
arcpy.AddField_management(in_featureclass, field_Name, field_Type, field_Precision, field_Scale)
arcpy.CalculateField_management(in_featureclass, field_Name, '!SHAPE.area@ACRES!', "PYTHON_9.3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment