I'm looking to create a simple button that calculates acres on selected polygons and can't quite find what I'm looking for. I read through this thread: automating a python script..., but found it wasn't quite what I am looking for. My Python skills are very near nil, I'm using ArcGIS 10.1 SP1 for Desktop (Build (3143).
I'm aware of !SHAPE.area@ACRES!, but need help getting into button form that resides on my toolbar.
EDIT: I've pieced some code together from several examples here & around the net. When I add the button to ArcGIS, highlight a polygon and click, nothing happens. Nothing. I'm obviously something and hope it's just one big hump to get me there. Below is the code thus far.
import arcpy
import pythonaddins
class CalculateSelectedAcreage(object):
"""Implementation for AcreageAddInTest_addin.CalcAcresSelected (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
# Implementation of OnClick method of Button's class
# Get the current map document and the first data frame.
mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
# Get the feature name to work with
in_featureclass = arcpy.GetParameterAsText(0)
# Set local variables
field_Name = "Area"
field_Type = "DOUBLE"
field_Precision = 18 # 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, as it does in DI Landtracs
arcpy.calculateField_management(in_featureclass, field_Name, 'float(!SHAPE.area@ACRES!)', "PYTHON_9.3")