Select to view content in your preferred language

Adding text in front of sequential numbering

6062
3
05-20-2014 01:26 PM
ZachHooper
Deactivated User
I found this script on this site, but I need to add text in front of the output. Is there a way to do this? I want to add "FIT-" in front of each incremental number.

rec=0
def autoIncrement():
global rec
pStart = 2555 #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

____________________________________________________________
autoIncrement()
Tags (2)
0 Kudos
3 Replies
JasonScheirer
Esri Alum
I'd just do it as a script:

featureclass = r"c:\my.gdb\myfc"
field = "idfield"

id = 1

with arcpy.da.UpdateCursor(featureclass, field) as cur:
    for row in cur:
        cur.updateRow(["FIT-{0}".format(id)])
    id += 1


but this modification to yours works too:

rec=0
def autoIncrement():
    global rec
    pStart = 2555 #adjust start value, if req'd
    pInterval = 1 #adjust interval value, if req'd
    if (rec == 0):
        rec = pStart
    else:
        rec = rec + pInterval
    return "FIT-{0}".format(rec)
0 Kudos
deleted-user-MS0lE1F_0-sy
Deactivated User
Need some help with something similar. I have fields 'numbered' in order like so, AW/01, AW/02, AW/03 and I need to add one to each; so new set would go AW/02, AW/03, AW/04. How do I run the autoIncrement ignoring the first 3 characters [0:2]?

Thanks for any help.

-Matt
0 Kudos
Zeke
by
Honored Contributor
Untested (i.e., try it on a copy first), give something like this a shot in Field Calculator, python parser, Show codeblock, :

def addone(fld):
    if not fld is None:
        temp = fld.split('/')
        num = int(temp[1]) + 1 # this will delete leading zeros
        newnum = str(num).zfill(2)  # change 2 to to however many zeros you want to pad the value by
        return "{0}/{1}".format(temp[0], newnum)


Then in the fld = block, put addone(!yourfield!). This code may need some work, but it's a start.
0 Kudos