AnsweredAssumed Answered

Summarize Unique Values on Parameter Update?

Question asked by dburton3 on Dec 6, 2018
Latest reply on Dec 6, 2018 by dburton3

So I have a python script that has two parameters

They are an input feature class and then an input field obtained from that feature class. How would I go about making a third parameter that's a boolean checklist of all unique values from that input field in that feature class, which updates after you select a field? I'd like it to have a checkbox but I recognize that I might have to have a dropdown->add sort of functionality instead. In the end I'd like to essentially choose values that I want to 'turn on' in a feature class by changing a value of 0 or 1, which I have set up in my python script:

 

import arcpy
## This code is to quickly choose which states get the selected color and which ones don't
inFC = arcpy.GetParameterAsText(0)
inFld = arcpy.GetParameterAsText(1)
stateList = arcpy.GetParameter(2)
## Check to see if it has the Lightswitch field
fldLst = arcpy.ListFields(inFC)
fldLst2 = []
x=0
for fld in fldLst:
    fldLst2.append(fld.name)
del fld
arcpy.AddMessage("It's pitch dark... you are likely to be eaten by a grue...")
arcpy.AddMessage(">Find lightswitch")
arcpy.AddMessage("You begin stumbling around in the dark, searching for a lightswitch")
for fld in fldLst2:
    if fld is not 'Lightswitch': ##If the field isn't a lightswitch, add a strike
        x+=1
    elif fld is 'Lightswitch':
        arcpy.AddMessage("You found the dang* Lightswitch and turned it on.")
        break
    elif x == len(fldLst2): ##If the field isn't a lightswitch and you've checked every field, build your own
        arcpy.AddMessage("You couldn't find the lightswitch, so instead you decide to build your own")
        arcpy.AddField_management(inFC,'Lightswitch','SHORT',1)
        break
with arcpy.da.UpdateCursor(inFC,[inFld,'Lightswitch']) as cursor:
    for state in cursor:
        state[1]=0 ##Default switch is set to off
        cursor.updateRow(state)
        for stat in stateList: ##Check it against selected states, if it's in the selected state list, turn it on
            if state[0]!=stat:
                continue
            elif state[0]==stat:
                state[1]=1
                cursor.updateRow(state)

Outcomes