I am trying to create a Python Toolbox and I need to load some chekboxes to a parameter (param2
) after selecting a value in previous parameter (param1
).
As you can see I have name of states in param1
and need to load a code like this after changing on param1
inFeature = parameters[0].valueAsText
slectedCounty = parameters[1].valueAsText
counties = []
def unique_values(table , field):
with arcpy.da.SearchCursor(table, [field], '"NAME_1" = \''+slectedCounty+'\'') as cursor:
return sorted({row[0] for row in cursor})
uniques = unique_values(inFeature, 'NAME_2')
for unique in uniques:
counties.append(unique)
# Now Load the checkboxes
param1.filter.list = counties
Here is the code
def getParameterInfo(self):
"""Define parameter definitions"""
param0 = arcpy.Parameter(displayName="Feature Class",name="in_fc", datatype="Shapefile", parameterType="Required", direction="Input")
param1 = arcpy.Parameter(displayName="States",name="st",datatype="String", multiValue="False", parameterType="Required", direction="Input")
param1.filter.list = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']
param2 = arcpy.Parameter(displayName="Counties",name="countyName",datatype="String", multiValue="true", parameterType="Required", direction="Input")
params = [param0, param1, param2]
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return