import arcpy import pythonaddins class BlueBird(object): """Implementation for BlueBird.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): arcpy.SelectLayerByLocation_management("Address Points","COMPLETELY_WITHIN","Parcels") #insert if statement checking that only one parcel is selected to prevent selecting all address points with arcpy.da.SearchCursor("Parcels",'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("Parcels",'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
Solved! Go to Solution.
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 arcpy.SelectLayerByLocation_management(addressLayer,"COMPLETELY_WITHIN",parcelsLayer)
import arcpy import pythonaddins class BlueBird(object): """Implementation for BlueBird.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): arcpy.SelectLayerByLocation_management("Address Points","COMPLETELY_WITHIN","Parcels")
import arcpy import pythonaddins class BlueBird(object): """Implementation for BlueBird.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): arcpy.SelectLayerByLocation_management("Address Points","COMPLETELY_WITHIN","Parcels")
import arcpy import pythonaddins class BlueBird(object): """Implementation for BlueBird.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): print "Hello world!"
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 arcpy.SelectLayerByLocation_management(addressLayer,"COMPLETELY_WITHIN",parcelsLayer)
That makes such an enormous amount of sense...
I'll give it a go in the morning!
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"