I hoped I could pick your brain a little bit more.The script as I have it now does what it's supposed to, but only if one and only one parcel polygon is selected.If multiple polygons are selected, it will simply copy the PIN and TMS fields from the first parcel to all address points within the selection (not good!). If no polygons are selected, it will select all address points in the layer (yikes!) and behave similarly to above.So my question is two-fold here:a) How can we safeguard against hitting the button with no parcels selected and the script running on all address points in the layer?Given a number of selected polygons (x), if (x > 0) then perform this block of script, else end?b) Given a number of selected polygons (x > 0), how can I make the script iterate and apply appropriate PIN numbers?I thought of something like:import arcpy
import pythonaddins
class BlueBird(object):
"""Implementation for BlueBird.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
#Get the current map document and the first data frame.
mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Address Points":
addressLayer = lyr
if lyr.name == "Parcels":
parcelslayer = lyr
#make sure user has at least 1 parcel selected, else end
if selectedFeatures > 0:
#select by location outside of loop to save time
arcpy.SelectLayerByLocation_management("Address Points","COMPLETELY_WITHIN","Parcels")
#create loop to iterate through number of selected parcels
selectedFeatures = arcpy.MakeFeatureLayer_Management("Parcels", "selected")
for rows in selectedFeatures:
with arcpy.da.SearchCursor("selected",'PIN') as cursor:
for row in cursor:
storedPIN = row[0]
with arcpy.da.UpdateCursor("Address Points",'PIN') as cursor:
for row in cursor:
row[0] = storedPIN
cursor.updateRow(row)
del cursor
with arcpy.da.SearchCursor("selected",'TMS') as cursor:
for row in cursor:
storedTMS = row[0]
with arcpy.da.UpdateCursor("Address Points",'TMS') as cursor:
for row in cursor:
row[0] = storedTMS
cursor.updateRow(row)
del cursor, storedPIN, storedTMS
#delete selected layer after looping finished
del selected
else:
MessageBoxCommand(?) "Please select at least one parcel"
I'm sure the above is all sorts of a mess, apologies.