I want to have a Field type parameter draw values from one of two other Feature Class parameters in my custom tool. When the user selects option 1, FC 1 is enabled and FC 2 is greyed out, and vice versa for option 2. When option 1 is selected, the Field parameter finds the values and populates the dropdown, but when option 2 is selected the dropdown is blank. I need to add code into the ToolValidator class to change the dependency of the Field parameter from FC 1 to FC 2, depending on which is enabled. Here is my code:# param[1] is the "option", param[2] and param[4] are FC1 and FC2, and param[9] is the Field
class ToolValidator:
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
import arcpy
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
if self.params[1].value == "Use Existing Intersect":
self.params[9].parameterDependencies = [2]
elif self.params[1].value == "Build New Intersect":
self.params[9].parameterDependencies = [4]
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if self.params[1].value == "Use Existing Intersect":
self.params[2].enabled = True
self.params[3].enabled = False
self.params[4].enabled = False
self.params[5].enabled = False
elif self.params[1].value == "Build New Intersect":
self.params[2].enabled = False
self.params[3].enabled = True
self.params[4].enabled = True
self.params[5].enabled = True
else:
self.params[2].enabled = False
self.params[3].enabled = False
self.params[4].enabled = False
self.params[5].enabled = False
Also, a side question: can the ToolValidator class code be added to my script code, or must it be edited within the tool properties?Any help on this would be much appreciated.