Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

calculate the value of a record (an unique id), if the record is selected?

$
0
0
Is there a way to calculate the value of a record (an unique id), if the record is selected? Right now I have something that calculates a sequential unique id but the records have to be unselected. Thanks!!!

Code:


    arcpy.SelectLayerByAttribute_management("Stewardship", "CLEAR_SELECTION")
##
    filter = 'NOT SequenceNumber IS NULL' #filter for non-Null values
    cur1 = arcpy.UpdateCursor("Stewardship", filter, "", "", "SequenceNumber A") # FILE should be updated to the file you're working with

# Iterate through rows and get highest ID values
    high_id = 0
    for row1 in cur1:
        if high_id < row1.SequenceNumber:
            high_id = row1.SequenceNumber


    filter = 'SequenceNumber IS NULL' #filter for Null values
    cur2 = arcpy.UpdateCursor("Stewardship", filter)

    # Iterate through rows and update values
    i = high_id
    for row2 in cur2:
        i += 1
        row2.SequenceNumber = (i)
        cur2.updateRow(row2)


Viewing all articles
Browse latest Browse all 2485

Trending Articles