3

Previous posts (such as Adding automated values to attribute field?) answer how to calculate sequential values in an attribute table. The posts all seem to rely on the process described in this ESRI Tech Support page:

https://support.esri.com/en/technical-article/000011137

Here are the article's details:

  1. Create a new short integer field.
  2. Set the Parser to Python.
  3. Select Show Codeblock.
  4. 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
    
  5. Paste the following code in the smaller box below the Pre-Logic Script Code:

    autoIncrement()
    
  6. Click OK.

But at 10.5.1 I can achieve the same results with this single line in the field calculator:

!FID! + 1

The results are exactly the same as the more complex ESRI-supplied code, even if the the table is sorted on a non-FID field and/or there is a selected set of records.

What am I missing here? Does the ESRI-supplied code do something that I'm not aware of?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 23, 2017 at 0:25
1
  • 1
    Fid + 1 valid for shapefiles only. Edited feature class in database will likely fail. Commented Dec 23, 2017 at 1:16

1 Answer 1

6

The Esri supplied code starts from 0 and increases by 1. Your method will do the same only if your FID starts at 0 and increases sequentially. An ObjectID or FID is system managed, so if you delete a record you will have gaps, and in a geodatabase you could have a feature class that has an ObjectID starting at 300000 (for example), so you're not going to get a straight 1,2,3,4 etc. from that using your code.

answered Dec 23, 2017 at 1:00
1
  • 1
    To add to this. The ESRI code will work on a selection. The FID + 1 won't. So has a few more applications. Commented Dec 24, 2017 at 7:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.