I want to iterate through a layer that has about 500 records. In my code, I'm using a definition query inside a for loop to iterate through a test list:
listx = [1,2,3,4,5]
My question (probably an elementary one), is how to just call out all records instead of manually typing all 500 object ID's? I want to iterate through all Object IDs, while ingesting each ID into the definition query. I thought trying [:] or [*] or [0:500] would work, but they don't.
import arcpy
from arcpy import mp
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Map")[0]
lyr1 = m.listLayers("No_Other")[0]
lyr2 = m.listLayers("No_Admin")[0]
#obid = "OBJECTID in (409, 764, 114, 776)"
obid = "OBJECTID = {}"
listx = [114, 409, 764, 776]
for oid in listx:
lyr2.definitionQuery = obid.format(oid)
arcpy.SelectLayerByLocation_management(lyr1, 'WITHIN_A_DISTANCE', lyr2, "150 Miles", 'ADD_TO_SELECTION', 'NOT_INVERT')
lyr2.definitionQuert = None
print(lyr2.definitionQuery)