i have python tool box with definition query tool, the tool activate definition query on multiple layers
In running into hard wall when trying to display only the fields that mutual to the different layers
When try to display the list of the fields the dialog shows only few fields and not all
I'm testing it on 2 similar layers with 90 fields. Turned off 3 in one layer and the dialog show only 4 instead of 87
With no filter i get all the fields in the first layer
how to let the user see only the mutual
list of fileds?
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].values:
all_layers_field_list = []
for layer in parameters[0].values:
field_names = [f.name for f in arcpy.da.Describe(layer.name)["fields"]]
all_layers_field_list.append(field_names)
list_fields = list(set(all_layers_field_list[0]).intersection(*all_layers_field_list[1:]))
parameters[1].filter.list = list_fields
if parameters[1].value:
field_values =list(set([row[0] for row in arcpy.da.SearchCursor(parameters[0].values[0], [parameters[1].valueAsText],f"{parameters[1].valueAsText} IS NOT NULL")]))
parameters[2].filter.list = field_values
return
I don't know what your *all_layers.... is all about
a = list("abcdefg")
b = list("bcdfghij")
a
['a', 'b', 'c', 'd', 'e', 'f', 'g']
b
['b', 'c', 'd', 'f', 'g', 'h', 'i', 'j']
set(a).intersection(b)
{'b', 'c', 'd', 'f', 'g'}
set(a).intersection(*b)
set()
*all_layer_field_list its list containg the list of fields of eace layer
the intesection works the problem the list of fields in the drop down dont contain the full list
I was pointing out that the starred expression (line 14) yielded erroneous results
im working with list of list becuse i dont know how many layer the user works with
this woks with the list of list
a = list("abcdefg")
b = list("bcdfghij")
d = [a,b]
set(d[0]).intersection(*d)
{'b', 'c', 'd', 'f', 'g'}
or with list of set its that way:
set.intersection(*d)