Refer to cell in attribute table with field calculator

1051
4
09-12-2019 07:43 AM
HaakonJørlo_Haugerud
New Contributor II

Hi

Im trying to assign values to a field by choosing a start value for a certain ID and having an increment and let the other field ID's automatically update with values depending on the start value and increment. 

This involves referencing to the "row" or ID of the Field where i want the numbering to start. How do I update other rows in a field to make them dependent on a certain cell in the attribute table?

Thanks,

Br

Haakon Haugerud

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

if you are using cursors, you will have to do it twice... the first time to get the value for the ID you want to use as the base, then again (reset the cursor may be needed) to use the value.

You might have better luck exporting your fields to a numpy array (TableToNumPyArray), do the work there then use ExtendTable to joining the results back.

0 Kudos
HaakonJørlo_Haugerud
New Contributor II

Hi Dan,

Thanks for the answer.

So I found a code that might work:

But get error: "parameter is missing or invalid"

0 Kudos
DanPatterson_Retired
MVP Emeritus

You have a calling issue and some indentation issues.

SrtVal = 20
def autoincrement():
    global SrtVal
    pInterval = 20
    if SrtVal == 20:
        SrtVal += pInterval
    else:
        SrtVal += pInterval
    return SrtVal
    

Chainage = autoincrement()  # ---- note the ()

Chainage
40
0 Kudos
HaakonJørlo_Haugerud
New Contributor II

Ok, thank you. Do you have a suggestion on what needs to be changed to solve this?

0 Kudos