Hello all,
I have a Python Tool that has two input Parameters, both of which are ValueLists. The choices available in the second list are dependent on the choice made in the first list. Setting this up is not a problem; however, when I run the tool and change the selection in the first ValueList, I can no longer make a selection in the second ValueList; it firmly remains on the first item which I set in the updateParameters method when I changed the contents of the second ValueList.
I'm including a sample Tool to show what I mean. If you run it, you'll see that you can easily change the selection in the second dropdown...until you change the selection in the first dropdown, at which point, you can no longer do so in the second.
I'm currently using 10.1 with no option to upgrade at this time. If this is a bug, can anyone tell me if it continues to be a bug in 10.3? Or, if there is merely something wrong with how I am setting the current value for the second ValueList in the updateParameters when I change the list contents, I'd appreciate hearing from you.
Cheers,
jtm
import arcpy class Toolbox(object): def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Toolbox" self.alias = "" # List of tool classes associated with this toolbox self.tools = [Tool] class Tool(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "Tool" self.description = "" self.canRunInBackground = False self.productDisplayName = "Product" self.productValueList=[ "Precipitation - Accumulated", "Precipitation - Percent of Normal", "Temperature" ] self.productEnum=["ac","av","tmp"] self.productValue = "Precipitation - Accumulated" self.typeEnum=["ac","av","tmp"] self.typeValueLists = { "ac": { "ay": "Agricultural Year", "gs": "Growing Season" }, "av": { "ay": "Agricultural Year", "gs": "Growing Season" }, "tmp":{ "1ti": "1-day Minimums", "1tx": "1-day Maximums", "7ti": "7-day Minimums", "7tx": "7-day Maximums" } } def getParameterInfo(self): """Define parameter definitions""" product = arcpy.Parameter( displayName=self.productDisplayName, name="paramStrProduct", datatype="GPString", parameterType="Required", direction="Input" ) product.filter.type = "ValueList" product.filter.list = self.productValueList product.value = self.productValue prodtype = arcpy.Parameter( displayName=self.productDisplayName, name="paramStrType", datatype="GPString", parameterType="Required", direction="Input" ) prodtype.filter.type = "ValueList" prodtypeList = self.typeValueLists["ac"].values() prodtype.filter.list = prodtypeList prodtype.value = prodtypeList[0] return [product, prodtype] 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.""" if parameters[0].altered: if parameters[0].value == self.productValueList[0]: prodtypeList = self.typeValueLists[self.typeEnum[0]].values() elif parameters[0].value == self.productValueList[1]: prodtypeList = self.typeValueLists[self.typeEnum[1]].values() elif parameters[0].value == self.productValueList[2]: prodtypeList = self.typeValueLists[self.typeEnum[2]].values() parameters[1].filter.list = prodtypeList parameters[1].value = prodtypeList[0] return def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" return def execute(self, parameters, messages): """The source code of the tool.""" arcpy.AddMessage(parameters[0].value) arcpy.AddMessage(parameters[1].value) return