I have a script that uses one layer to select features of a second layer in the first loop of the script. When the second layer's features are selected, I have a second loop that is supposed to update the fields on the first layer in the first loop. Is there a specific way of using an updateCursor or setValue to affect the nesting loop?
The second loop seems to get stuck. Shouldn't the loop only run through the selected features then continue back to the first loop?
Code:
for row1 in rows1:
count = 1
print "row %d" %parcelrow
parcelrow = parcelrow +1
selectcount = 0
currentPIN = row1.getValue(selectField)
arcpy.SelectLayerByAttribute_management(mapLyr1, "NEW_SELECTION", "\"%s\" = '%s'" %(selectField, currentPIN))
print currentPIN
arcpy.SelectLayerByAttribute_management(mapLyr2, "ADD_TO_SELECTION", "\"%s\" = '%s'" %(selectField, currentPIN))
selectcount = int(arcpy.GetCount_management(mapLyr2).getOutput(0))
print "%d points selected" %selectcount
if selectcount == 0:
arcpy.SelectLayerByAttribute_management(mapLyr1, "CLEAR_SELECTION")
pass
else:
for row2 in rows2:
hydrantfield = copytoField + "%d" %count
print "filling field " + hydrantfield
hydrID = row2.getValue(copyField)
#This setValue is supposed to update mayLyr1
row1.setValue(hydrantfield, hydrID)
rows1.updateRow(row1)
count = count + 1
arcpy.SelectLayerByAttribute_management(mapLyr1, "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(mapLyr2, "CLEAR_SELECTION")