Field Calculations

828
4
Jump to solution
03-04-2020 01:49 PM
JamesBushOpelika
New Contributor III

Can anyone help me with a field calculation script?

I have a field for sewer lines that has a unique code that increases by one for every new line added we typically have dozens of line segments added at a time. I would like to automate this field entry. 

last existing field ex 'SSP1000' New feature field would become 'SSP1001"

I am green with python, thanks in advance!

James Bush
jabush@opelika-al.gov
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

last = 8  # ---- change me
def seq_cal():
    """change last = 1 line to show last """
    global last
    a = 1
    if last == 0:
        last = a
    else:
        last = last + a
    return "SSP{:>04}".format(last)

python parser

you need a code block

emulate the above

highlight the rows you want to calculate

change the last = .... line to enter your previous value

View solution in original post

4 Replies
DanPatterson_Retired
MVP Emeritus

last = 8  # ---- change me
def seq_cal():
    """change last = 1 line to show last """
    global last
    a = 1
    if last == 0:
        last = a
    else:
        last = last + a
    return "SSP{:>04}".format(last)

python parser

you need a code block

emulate the above

highlight the rows you want to calculate

change the last = .... line to enter your previous value

JamesBushOpelika
New Contributor III

Dan,

Thanks for the response. I am still learning python. so the script should look like this for my data?

James Bush
jabush@opelika-al.gov
0 Kudos
JamesBushOpelika
New Contributor III

I have verified it. It works like a charm! You the Man!

James Bush
jabush@opelika-al.gov
0 Kudos
DanPatterson_Retired
MVP Emeritus

Glad it worked out James

0 Kudos