1

I'm trying to modify the autoIncrement() python script to auto number based on another field. For example, I need the autoincrement to restart when the field "STD_ID" changes value. This is my attempt but I'm not getting the results I need.

rec=0
stand = "STD_ID"
stand2 = "STD_ID"
def autoIncrement():
    global rec
    global stand
    global stand2
    pStart = 1 #adjust start value, if req'd 
    pInterval = 1 #adjust interval value, if req'd
    stand2 = "STD_ID"
    if (rec == 0): 
        rec = pStart 
    elif (stand2 == stand): 
        rec = rec + pInterval  
    else:
        rec = 1
        stand = "STD_ID"  
    return rec
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Jeff
  • 11
  • 1
  • 1
    Welcome to GIS SE! As a new user please take the [tour] to learn about our focused Q&A format. Which GIS software are you using? Please [edit] your question to include this info. – Midavalo Mar 16 '17 at 22:41
  • "I'm not getting the results I need" - What are the results you are getting, and how do they differ from what you need? – Midavalo Mar 16 '17 at 22:41
  • 1
    Your else will never be hit, as elif stand2 == stand will always be true (as far as I can tell). the values for these two parameters never change from STD_ID – Midavalo Mar 16 '17 at 22:44
  • So you want each instance of 'std_id' to get a unique contiguous value.. is that correct? How are you calling this? Is it in a python script or field calculator? – Michael Stimson Mar 16 '17 at 22:44
  • @MichaelMiles-Stimson says Field Calculator in the question title... – Midavalo Mar 16 '17 at 22:45
  • I'm using ArcGIS 10.4.1. – Jeff Mar 16 '17 at 22:56
  • Within ArcGIS 10.4.1, I'm attempting to use Field Calculator w/ Python expression type. You are correct that the elif stand2 == stand is always true. Therefore, the return value is 1 through 10 for example. What is the proper method in setting the second variable "stand2" to store the current records "STD_ID" value as it moves through each table row? I would like to have 1 for STD_ID = 1; next row 2 for STD_ID = 1; next row 1 for STD_ID = 2 etc... – Jeff Mar 16 '17 at 23:06
  • 1
    @Jeff Please [edit] your question to include additional information or clarification. – Midavalo Mar 16 '17 at 23:10
  • Field 1 = STD_ID – Jeff Mar 16 '17 at 23:18
  • Sorry for the duplicate question. I did not initially find the answer that I was looking for. The answer was found at: http://gis.stackexchange.com/questions/67916/generating-sequential-numbering-for-duplicate-values-in-a-field-sorted-by-object?rq=1 – Jeff Mar 16 '17 at 23:33

0 Answers0