Hello, I am just wondering if anyone tells me the way to get a count zero to exit from the while loop that uses arcpy.GetCount_management.
I set up for loop to go through a selection of intersection between polygon (ssLyr) layer and point geometry (cenPnt). Then, while the selected polygon count is greater than zero, a second for loop is carried out. But I would like to exit the while loop in case a specific value (neigbID == 9999) is returned during the second loop.
I tried a couple of ways; arcpy.management.SelectLayerByAttribute(ssLyr, "CLEAR_SELECTION"), del cursor1, arcpy.Delete_management(ssLyr) to get zero count from int(arcpy.GetCount_management(ssLyr).getOutput(0)) but none of them worked. Thank you in advance for any python coding help!
My code is here
for row in cursor:
cenPnt = row[1]
arcpy.management.SelectLayerByLocation(ssLyr, 'INTERSECT', cenPnt)
while int(arcpy.GetCount_management(ssLyr).getOutput(0)) > 0:
with arcpy.da.SearchCursor(ssLyr, fieldName2) as cursor1:
for row1 in cursor1:
biorID = row1[2]
neigbID = row1[3]
if neigbID == 9999:
print("\nError - Exit loop")
#Would like to get count zero here
#arcpy.management.SelectLayerByAttribute(ssLyr, "CLEAR_SELECTION")
#del cursor1
#arcpy.Delete_management(ssLyr)
print("Check count: ", int(arcpy.GetCount_management(ssLyr).getOutput(0)))