6

I would like to add a parameter as value table with one of the fields being a value list. The value table consist of 3 columns, namely "table","field","description", whereas "field" is a value list. The values of the value list shall depend on the input "table, thus change with each new entry. E.g. adding a table xyz to the value list should lead to a list of fields which can than be selected.

My code for now:

        def getParameterInfo(self):
            in_tables = arcpy.Parameter(
                displayName = "test",
                name = "test",
                datatype = "GPValueTable",
                parameterType = "Optional",
                direction = "Input")
            in_tables.columns = [["DETable", "table"],["GPString","field"],["GPString","description"]]
            in_tables.filters[1].type = 'ValueList'
            in_tables.filters[1].list = ["<marker spalte>"] #dummy list which is updated in updateParamters

        ...
        def updateParameters(self, parameters):
            if parameters[0].value and parameters[0].altered:
                fields_list = [field.name for field in arcpy.Describe(parameters[0].value[0][0]).fields]
                parameters[0].filters[1].list = fields_list #update of dummy list

This actually works but I always get the field list of the very first entry. I thought about using len in order to always get the last entry (which is a bit more useable but still not satisfying). What I would prefer is the identification of the selected row in order to dynamically update the value list with the related field names.

Is there a way to do that?

ArcGIS 10.3.1

Update: The problem with my parameters[0].value[0][0] solution is, that it is not working if the any of the other tables has other fields than the first one. the problem when working with len() is that an error occurs if one of the former selected fields does not exist in the last field list. Thus I changed my updateParameters method.

        if parameters[0].value and parameters[0].altered:
            all_tables_list = parameters[0].value
            number_of_tables = len(all_tables_list)
            i = 0
            fields_list_tmp = []
            for in_table in all_tables_list:
                fields_list_tmp.append([field.name for field in arcpy.Describe(parameters[0].value[i][0]).fields])
                i += 1
            fields_list = list(set([item for sublist in fields_list_tmp for item in sublist]))
            parameters[0].filters[1].list = fields_list

which basically creates a list with all existing fields in all selected tables.

1
  • Awesome kludged solution. I'm going to use something like this for allowing the user to pick a particular field from each input file. Thanks a lot!
    – Adam B
    Commented May 7, 2018 at 6:23

1 Answer 1

2

I don't have access to 10.3, but is it possible in the parameter.filters[] to set a dependency to the first column?

Otherwise, as you say, this is the line that is causing the problem.

parameters[0].value[0][0]

Since you are calling the first row first column. If you choose this route, then I think finding the len of the list might be your best option.

Alternatively, you could put the field as the first column, and pull out the DETable as a separate parameter then set the GPValueTable's dependency as that parameter. This might force the field selections to be the dependent on that first parameter. You can add a string column to store the name of the table and then use the updatemessages/parameters to check to update that column or as a name check. Sorry, I know that sounds a little convoluted.

There is an example here that may help conceptually: Creating a ValueTable with a column that has dependency

1
  • For now, I didn't find a possibility to set a dependency to the filters[].
    – Caro GI
    Commented May 17, 2016 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.