Hello!
I'm currently trying to create a button within arcmap that runs a set of if-then rules to fill in a blank field within the layer's attribute table. I've been able to do this in the field calculator with no problem, but in order to speed up the process, I would like to be able to run the process in one click rather than manually labeling.
My issue is that I don't know how to get it so that the button takes the already selected features and then proceeds to run the nested statements.
import arcpy
import pythonaddins
class BlockAnno(object):
"""Implementation for Test_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
lyr = pythonaddins.GetSelectedTOCLayerOrDataFrame()
with arcpy.da.UpdateCursor(lyr,["block", "sub_code"]) as blockanno:
if sub_code != '0000':
if sub_code != '0780':
if block[0:3].isdigit():
blockanno = str(block[0:3].lstrip('0'))
elif block[2].isalpha():
if block[0:2] == '00':
blockanno = str(block[0:].strip('0'))
cursor.updateRow()
return(BlockAnno)
I'm hoping this is feasible, but would appreciate any guidance or advice.