Select to view content in your preferred language

How to iterate over multiple workspace inputs in tool validation

1087
2
Jump to solution
08-26-2021 05:13 AM
MattHowe
Frequent Contributor

I have a tool that has a workspace parameter and accepts multiple values. In the tool validation script, I would like to list all feature classes found within all chosen workspaces in the second parameter. 

How do I iterate over the workspaces in the first parameter?

 

 

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:
    # something like below ?
    for ws in self.params[0].split(";"):

 

 

0 Kudos
1 Solution

Accepted Solutions
MattHowe
Frequent Contributor

Cheers Dan. Figured it out.

def updateParameters(self):
    # Modify parameter values and properties.
    # This gets called each time a parameter is modified, before 
    # standard validation.
    self.params[1].filter.list = []
    if self.params[0].altered:
        if self.params[0].value:
            fcs = []
            ws = self.params[0].values
            for item in ws:
                arcpy.env.workspace = item
                data = arcpy.da.Walk(item, datatype="FeatureClass")
                for dirpath, dirnames, filenames in data:
                    for filename in filenames:
                        fcs.append(filename)
        self.params[1].filter.list = fcs
    return

 It was the '.values' property of the multiple value parameter I was missing. 

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor

Walk—ArcGIS Pro | Documentation

Listing things using arcpy 

should pretty well cover the things you are looking for.  ListWorkspaces, ListFeatureclasses in conjunction with Walk 


... sort of retired...
MattHowe
Frequent Contributor

Cheers Dan. Figured it out.

def updateParameters(self):
    # Modify parameter values and properties.
    # This gets called each time a parameter is modified, before 
    # standard validation.
    self.params[1].filter.list = []
    if self.params[0].altered:
        if self.params[0].value:
            fcs = []
            ws = self.params[0].values
            for item in ws:
                arcpy.env.workspace = item
                data = arcpy.da.Walk(item, datatype="FeatureClass")
                for dirpath, dirnames, filenames in data:
                    for filename in filenames:
                        fcs.append(filename)
        self.params[1].filter.list = fcs
    return

 It was the '.values' property of the multiple value parameter I was missing.