Python Sequential Numbering

4770
11
Jump to solution
10-15-2021 02:16 PM
DavidForbuss1
Occasional Contributor III

Hi everyone!

I'm using the sequential numbering script in the field calculator, and I'm trying to modify it to iterate through field values from another field so that the sequence starts over for each of the unique other values.  My table looks like this -->>  I'm trying to generate a Name with a Basin ID as the prefix.  For now, I've been just manually selecting the basins and running the script for each one, but I'd like to be able to have the script run through them all at once:

DavidForbuss1_3-1634332431187.png

 

 

Script I'm using:

DavidForbuss1_1-1634332233141.png

 

 

SequentialNumber()

# Calculates a sequential number
# More calculator examples at esriurl.com/CalculatorExamples
rec=0
def SequentialNumber():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return "WA1MH"+str(rec).zfill(4)

I'm pretty rusty on python...any help would be appreciated!

Thanks,

David Forbuss

GIS Technician

Rogue Valley Sewer Services

P O Box 3130

Central Point OR 97502

541-664-6300

dforbuss@rvss.us

 

 

 

11 Replies
JoshuaBixby
MVP Esteemed Contributor

@DavidForbuss1, don't worry, @JoeBorgione  is going to be like Dan P. and be more active on Esri Community after he retires from his day job. 🙂

JoeBorgione
MVP Emeritus

I'm glad it worked for you.  For me, I much prefer to use an update cursor than the field calculator in this kind of situation.

With respect to retirement, it's in the very near future for me, so ask away!

That should just about do it....
0 Kudos