1

I want to know if anyone has a code to count +1 starting at a certain number for Field Calc. ArcGIS. (I.e. 04312, 04313) It also must keep the 0 in front.

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

    str(autoIncrement( )).zfill(12)

parsing error syntaxerror:invalid token (line 4)

1
  • Replace 040150117669 by 40150117669
    – FelixIP
    Commented Aug 19, 2015 at 21:06

1 Answer 1

1

Use 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

Call it using:

str(autoIncrement( )).zfill(5)

It will work on text field

3
  • you can update your question
    – FelixIP
    Commented Aug 19, 2015 at 20:50
  • this doesn't keep the 0 in front of the number. the 0 is crucial. any suggestions? Commented Aug 27, 2015 at 20:53
  • are you doing it on text field?
    – FelixIP
    Commented Aug 27, 2015 at 21:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.