5

i have a challenge with my time in my work, i have feature class called "Parcel" storing many data, i generated an autoIncrement number by using field calculator, in field "parcel code"

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

that i asked here before Adding automated values to attribute field?

i want to start number to 001......009, and 010.........099,

3

You need to use zfill function, like in the code below, zfill function fill zeros in the left of the string:

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 str(rec).zfill(3)
  • 1
    wooooooooooooooow, thank you very much @geogeek, you solved spend many time, instead of doing it manually, thank you again. – GIS Man Dec 24 '13 at 9:39
  • 1
    Here is a version that uses a generator function rather then a if and global gist.github.com/NathanW2/8113514 – Nathan W Dec 24 '13 at 13:44
  • ok, thank you very much@Nathan W, it is a good idea. – GIS Man Dec 24 '13 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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