Summarize Unique Values on Parameter Update?

12-06-2018 07:26 AM
New Contributor II

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 = []
for fld in fldLst:
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
    elif fld is 'Lightswitch':
        arcpy.AddMessage("You found the dang* Lightswitch and turned it on.")
    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")
with arcpy.da.UpdateCursor(inFC,[inFld,'Lightswitch']) as cursor:
    for state in cursor:
        state[1]=0 ##Default switch is set to off
        for stat in stateList: ##Check it against selected states, if it's in the selected state list, turn it on
            if state[0]!=stat:
            elif state[0]==stat:

0 Kudos
2 Replies
Esri Esteemed Contributor

Hi Devon,

For the 3rd parameter, set the Data Type to a String, Multivalue to Yes, and Filter to Value List:

You can then use Validation tab to populate this Value List:

def updateParameters(self):
  if self.params[0].value and self.params[1].value:
    self.params[2].filter.list = sorted({row[0] for row in arcpy.da.SearchCursor(self.params[0].value, self.params[1].value.value) if row[0]})

This will give you the following:

New Contributor II

Thank you so much!

0 Kudos