I'd like to populate two columns of a table of values string parameter in a custom Python tool (non Python toolbox) with fields names from two other parameters. In the example, the first column would have a list of fields from parameter 0, and the second column a list of fields from parameter 1. I only have the option of choosing one dependency in the parameter list (of which works great) but I also need the other parameter. How should Value Table parameters be handled in the validation script so each column's filter list can be defined?
def updateParameters(self):
# Modify parameter values and properties.
# This gets called each time a parameter is modified, before
# standard validation.
if self.params[0].altered and self.params[0].value:
source_field_list = [f.name for f in arcpy.ListFields(self.params[0].value)]
if self.params[1].altered and self.params[1].value:
target_field_list = [f.name for f in arcpy.ListFields(self.params[1].value)]
return
This gets the two field lists but just need to figure out how to give them as options in both columns.
Solved! Go to Solution.
Figured it out. I'd set the individual column data types to field when they should have been strings then set the filter. Validation code below does the job.
def updateParameters(self):
# Modify parameter values and properties.
# This gets called each time a parameter is modified, before
# standard validation.
if self.params[0].altered and self.params[0].value:
source_field_list = [f.name for f in arcpy.ListFields(self.params[0].value)]
self.params[2].filters[0].list = source_field_list
if self.params[1].altered and self.params[1].value:
target_field_list = [f.name for f in arcpy.ListFields(self.params[1].value)]
self.params[2].filters[1].list = target_field_list
return
Figured it out. I'd set the individual column data types to field when they should have been strings then set the filter. Validation code below does the job.
def updateParameters(self):
# Modify parameter values and properties.
# This gets called each time a parameter is modified, before
# standard validation.
if self.params[0].altered and self.params[0].value:
source_field_list = [f.name for f in arcpy.ListFields(self.params[0].value)]
self.params[2].filters[0].list = source_field_list
if self.params[1].altered and self.params[1].value:
target_field_list = [f.name for f in arcpy.ListFields(self.params[1].value)]
self.params[2].filters[1].list = target_field_list
return
Thanks for posting this. ESRI should consider adding this to their help documentation. Without having preset filters created you can't set them via arcpy.
def initializeParameters(self):
self.params[0].filters[0].list = ['test']
# error returned: AttributeError: ParameterObject: Get attribute: filters does not exist
Help doc states the following, which isn't true from arcpy. If you add a list to a ValueTable that doesn't have a filter predefined you get errors.
By adding values to an empty filter, you activate the filter, and the user's choices are limited by the contents of the filter. (link)