I am trying to apply Sequential numbering in groups via a for loop. The loop should select a group of rows, apply sequential number to just those rows in the group, then move on to the next selected group. Here's the code I was trying to use in the Python Window in Pro.
for cable in myValues:
arcpy.management.SelectLayerByAttribute(fiber, "NEW_SELECTION", "cable_name = '%s'"% cable, None)
arcpy.management.CalculateField(fiber, "SegmentID", "SequentialNumber()", "PYTHON3",
rec=0
def SequentialNumber():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
,'TEXT')
The process works manually, but I'm not sure what I'm missing. I think the issue is formatting the code block of the SequentialNumber function within the Calculate Attributes run inside the for loop. Any help on this is greatly appreciated!