Field Calculations

409
4
Jump to solution
03-04-2020 01:49 PM
JamesBushOpelika
New Contributor II

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!

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

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 Esteemed Contributor

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 II

Dan,

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

0 Kudos
JamesBushOpelika
New Contributor II

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

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Glad it worked out James

0 Kudos