[GIS] How to create button that calculates acres on selected polygon features

arcgis-10.1arcgis-desktoparcpyfield-calculatorpython-addin

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

Best Answer

Getting a script to a button is pretty simple.

Go to the menu Customize --> Customize Mode --> Commands (tab)

Once on the Commands tab, scroll to the bottom of "Categories" and choose:

[Geoprocessing Tools]

and click on "Add Tools..."

Find the Script Tool you want to add.

The tool should be in the "Commands:" window, just drag it onto a toolbar and voila! You have it in a button form.

...

However, there are other things that you should clarify. How you see the Acres depends on the code in you Script Tool. Do you have a Tool yet? Or do you need help with that as well?

Related Question