Sorting feature class to calculate sequential ID field using ArcGIS Field Calculator?
Try using Sort (Data Management) followed by Calculate Field (Data Management) using the auto-increment example on the Calculate Field examples help page.
If you need to sort the data and update it in-place (no intermediate dataset), then I think you would have to use an UpdateCursor which can also sort by a field.
I used ModelBuilder and I did a field sort followed by calculate field using the sort code below and it worked great.
Previously, I had tried these two steps outside of ModelBuilder and it failed.
Expression:
autoIncrement()
Expression Type: PYTHON_9.3
Code Block:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec