Recently I was creating a HUGE figure which needed to reference all the features in the map with a number, so, as I would normally, I went to the attribute table, created a new field and opened up the ArcGIS Field Calculator, then opened up Ian Ko’s Easy Calculate (EC50 to you REAL GIS nerds) in preparation to use the “REC” command…..only it didn’t work
It turns out that EC50 doesn’t work with ArcGIS 10.1, so what did I do?……I used Python!!
Here is the ESRI resource page on how to create sequential numbers, easy peasy – even a Python noob like me got it to work!!
HowTo: Create sequential numbers in a field using Python in the Field Calculator
Article ID: | 38517 |
---|---|
Software: | ArcGIS – ArcEditor 10 ArcGIS – ArcInfo 10 ArcGIS – ArcView 10 |
Platforms: | N/A |
Summary
Instructions provided describe how to create sequential numbers in a field using Python in the Field Calculator.
Procedure

- Create a new short integer field.
- Set the Parser to Python.
- Select Show Codeblock.
- Paste the following into the Pre-Logic Script Code:
rec=0 def autoIncrement(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec += pInterval return rec
- Paste the following code in the smaller box below the Pre-Logic Script Code:
autoIncrement()
- Click OK.
Thank you so much. It works very well.
you are a hero
Thank you!!
is there a way to create a sequence number begining in the left and increasing as you move to the Right? I’m not real familar with Python.
Hi,
Not quite sure what you mean. If you mean, is there a way to sequentially create a number along a line when it is in reverse order, you can do this in ArcGIS editing by selecting the line, right clicking and reverse order. Then apply the sequence routine.
If you mean whether you can apply this across multiple fields, so that field A = 0, B=1, C=2, then you can do this easily in excel and joining the tables.
Is it a multipoint? …..you might need to change the format first
hello,
the numbering works fine, but is it also possible to have text in front of the number?
An example would be
QU-GO1
QU-GO2
QU-GO3
…
QU-GOn
Apologies for the delay, just returned from paternity….things have been a little hectic!!
Yes, you can put text in front, use =”text here”&FID
Thank you this is a very useful script and my first fling with python. I want to start the sequence with zero but when I change pstart to zero I get all zeros. I have changed many of the parameters but nothing seems to work. I can get a nice list starting with any value other than zero and any increment that I like, I just can’t make the first feature have a zero value. Any thoughts?
Thank you
Cheat! Create a new field and run a process which takes 1 away from the culprit field 😛
If the field is ID, then create a new column and run “[ID]-1″….then delete the original field.
Not the best and I am sure that I could wrap it up in the python given time. Does that help?
Thank you very much- sometimes the simple solutions are the hardest to find.
u r a star! thank you so much!
Worthless information!
For an “unsorted” table we can obviously just make “NewIDField” = ObjectID. But how do we sequentially number a “SORTED” field? Everything I find online gives me this same (completely unnecessary) python script.
It is worthless information now…..especially now that there is a tool to add an ID field to attribute tables
Hello There.
Thanks for sharing this code.
Would you like to explain me how to this :
Peter says:
June 11, 2014 at 11:49 am
hello,
the numbering works fine, but is it also possible to have text in front of the number?
An example would be
QU-GO1
QU-GO2
QU-GO3
…
QU-GOn
Reply
dragons8mycat says:
July 9, 2014 at 7:17 am
Apologies for the delay, just returned from paternity….things have been a little hectic!!
Yes, you can put text in front, use =”text here”&FID
where i put this code ( use =”text here”&FID) on your first code ?
thanks
Just to finish this thread, ArcGIS 10.5 & ArcGIS Pro both have a “create incremental field” option:
http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/add-incrementing-id-field.htm
Hopefully all our issues are a thing of the past!