Paste the code exactly as written below within the code tags.Pre-Logic Codeblock: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
The Label field should be a Long Integer field for good measure.
I recommend that you only use the Field Calculator option to maintain sequential numbers. The script option as written will overwrite every sequential number in the Label field every time it is run. It does not use any layer that is in any map or any selection in a layer to limit the records that it overwrites. That is because you are supplying a path to the feature class on disk, not a connection to the layer in your open map. A few other lines of code would be needed to connect to the layer in your currently open map and any selection it may contain.
The Field Calculator option is designed to work on a layer in your currently open map and will respect any selection of records you may have chosen. This allows you to avoid overwriting previously assigned sequential numbers and continue the numbering only for records that have no Label value. So even if you get both to work, I would only go with the Field Calculator after the initial sequential number assignment for any continuing maintenance.
The negative:
It works and create a string but not what I want it create the same than
label=[FID]+1
and not a
label=[raw ofter sorting]+1
i wanted
AM following this post and am having sequential numbering problems.
Simply I need to take about 5000 features all labeled XTLF_XTLF0001000000* and make them read
XTLF_XTLF00010000001.........XTLF_XTLF00010004934
Thanks in advance
The code below should work to sequence the numbers in the format you want as long as it is for a single prefix and the sequence does not restart for different groups of records:
Parser: Python
Show Codeblock: checked
Pre-Logic Codeblock:
rec=0
def autoIncrement():
global rec
pStart = 10000001 # adjust start value, if req'd
pInterval = 1 # adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return "XTLF_XTLF{011d}".format(rec)
Expression (Label): autoIncrement()