Identify Next Number in Sequence

907
2
Jump to solution
08-05-2020 12:30 PM
ModernElectric
Occasional Contributor III

I have a series of different Feature Classes and most of them I have assigned a Company Tag/Number and they are in sequential order. What I would like to do is to write a Python script to identify what the next number would be on a given Feature Class's field. If the last sequential number of 2345, I would want the script to "print" 2346. Need to know how to get started. 

Want to write a Python script to achieve this.

Thank You

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

Perhaps something like this would give you an idea.  It is using the OBJECTID; just substitute your tag number field in lines 1 and 2:

value = arcpy.da.SearchCursor(feature, ["OBJECTID"],
                              sql_clause = (None, 'ORDER BY OBJECTID DESC')
                              ).next()[0]

print value
# 19

print value + 1
# 20‍‍‍‍‍‍‍‍‍

If the tag numbers are spread across several features - that is number 1, 3, 4, etc. can be in one feature, and 2, 5 are in another - you may need to use a table or text file to store the last number used.  Then read that table/file, issue tag numbers, then update the table/file with the last used number.

View solution in original post

0 Kudos
2 Replies
RandyBurton
MVP Alum

Perhaps something like this would give you an idea.  It is using the OBJECTID; just substitute your tag number field in lines 1 and 2:

value = arcpy.da.SearchCursor(feature, ["OBJECTID"],
                              sql_clause = (None, 'ORDER BY OBJECTID DESC')
                              ).next()[0]

print value
# 19

print value + 1
# 20‍‍‍‍‍‍‍‍‍

If the tag numbers are spread across several features - that is number 1, 3, 4, etc. can be in one feature, and 2, 5 are in another - you may need to use a table or text file to store the last number used.  Then read that table/file, issue tag numbers, then update the table/file with the last used number.

0 Kudos
ModernElectric
Occasional Contributor III

Thank You Randy. That is what I was looking for.

0 Kudos