Apologies, I forgot to post my finished script. Here it is for anyone interested. It basically allows an unexperienced ArcGIS user to select by attributes and returns the number of features meeting the specified criteria. It was a fun exercise, but I kind of doubt it will benefit any of you that much.import arcpy
import pythonaddins
class ButtonClass4(object):
"""Implementation for Totals_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
desc = arcpy.Describe(fc)
if desc.shapeType == "Point":
arcpy.MakeFeatureLayer_management(fc, "pointfeats", '"' + attName + '"' + ' = ' + "'" + valName + "'")
count = arcpy.GetCount_management("pointfeats")
print str(count) + " FEATURES WITH " + str(attName) + " EQUAL TO " + (str(valName)).upper()
arcpy.Delete_management("pointfeats")
elif desc.shapeType == "Polyline":
arcpy.MakeFeatureLayer_management(fc, "linefeats", '"' + attName + '"' + ' = ' + "'" + valName + "'")
lengths = []
curs = arcpy.da.SearchCursor("linefeats", "Shape_Length")
for cur in curs:
lengths.append(cur)
floatLengths = [float(e[0]) for e in lengths]
totalLength = sum(floatLengths)
print str(round(totalLength,2)) + " TOTAL LINEAR FEET"
arcpy.Delete_management("linefeats")
elif desc.shapeType == "Polygon":
arcpy.MakeFeatureLayer_management(fc, "polygonfeats", '"' + attName + '"' + ' = ' + "'" + valName + "'")
areas = []
curs = arcpy.da.SearchCursor("polygonfeats", "SHAPE_Area")
for cur in curs:
areas.append(cur)
floatAreas = [float(e[0]) for e in areas]
totalArea = sum(floatAreas)
print str(round(totalArea,2)) + " TOTAL SQUARE FEET"
arcpy.Delete_management("polygonfeats")
else:
print "Calculation can not be performed"
class ComboBoxClass1(object):
"""Implementation for Totals_addin.combobox (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWW'
def onFocus(self, focused):
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
self.items.append(layer.name)
def onSelChange(self, selection):
global fc
fc = arcpy.mapping.ListLayers(self.mxd, selection)[0]
class ComboBoxClass2(object):
"""Implementation for Totals_addin.combobox_1 (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWW'
def onFocus(self, focused):
if focused:
fields = arcpy.ListFields(fc)
self.items = []
for field in fields:
self.items.append(field.name)
def onSelChange(self, selection):
global attName
global attribute
attribute = arcpy.ListFields(fc, selection)[0]
attName = attribute.name
class ComboBoxClass3(object):
"""Implementation for Totals_addin.combobox_2 (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWW'
def onFocus(self, focused):
if focused:
values = [row[0] for row in arcpy.da.SearchCursor(fc, attName)]
uniqueValues = set(values)
self.items = []
for uniqueValue in uniqueValues:
self.items.append(uniqueValue)
def onSelChange(self, selection):
global valName
val = (self.items, selection)[1]
valName = str(val)