Select to view content in your preferred language

Populate two columns of a value table parameter with field names derived from two other parameters

1174
2
Jump to solution
09-25-2023 02:33 AM
MattHowe
Frequent Contributor

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?

MattHowe_0-1695634269795.png

 

    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.

 

1 Solution

Accepted Solutions
MattHowe
Frequent Contributor

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.

MattHowe_0-1695645025731.png 

MattHowe_1-1695645051831.png

    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

 

View solution in original post

2 Replies
MattHowe
Frequent Contributor

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.

MattHowe_0-1695645025731.png 

MattHowe_1-1695645051831.png

    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

 

PhilLarkin1
Frequent Contributor

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)