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.

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  
        rec = 1
        stand = "STD_ID"  
    return rec
  • 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
  • 1
    @Jeff Please edit your question to include additional information or clarification. – Midavalo Mar 16 '17 at 23:10