AnsweredAssumed Answered

How is Auto Increment supposed to work?

Question asked by mlhotz on Aug 22, 2016
Latest reply on Aug 25, 2016 by mlhotz

I have been away from Python scripting for a few years and am slowly working myself back into it.  I have been trying to set up an auto increment field in ArcGIS using Field Calculator.  The advice I have gleaned so far is to apply the code below in the Field Calculator (I have been using the Python Parser, but I'm not sure if this is the best solution, or if it even matters):


Pre-Logic Script Code:


def autoIncrement():
global rec
pStart = 1
pInterval = 1
if (rec == 0):
rec = pStart
rec += pInterval
return rec


Field updating (I have a temporary short integer field called "Test"):




I can calc the Test field using this script, and it does work.  However, it won't update the attribute table (record) automatically whenever I add a new point to the feature class.


Does anyone have any suggestions on what I'm missing, and what I need to add to my code to make this work?  I just need this field/record to update every time I add a point.  I have been using the OBJECTID field for an initial value to see if I can get that to work, but ultimately the user would like to see a concatenation of "TEXT-" + !OBJECTID!, which I'm sure I can work on once I get a simpler version working properly.