I'm having strange problem with Iterate Multivalue in Model Builder. The model is partially based on Generating a multivalue choice list example.
What I'm trying to do is show filtered layer list where user will be able to select some of them. For that I'm using Script Tool with 1 Input Multivalue string parameter, and 1 Derived Multivalue Any Value parameter.
Then selected layers names (multivalue variable) are used in Iterate Multivalue where each iterated value is used in Calculate Value. Layers are filtered in ToolValidator.
Now, the problem is that Iterate Multivalue doesn't iterate values. Instead it runs just one loop and passes one value which is a string with all selected layer names separated by semicolon.
ToolValidator's UpdateParameters code
if not self.params[0].altered:
mxd = arcpy.mapping.MapDocument("CURRENT")
dataframe = arcpy.mapping.ListDataFrames(mxd)[0]
layers = set()
for lyr in arcpy.mapping.ListLayers(mxd, "", dataframe):
if lyr.visible == True:
desc = arcpy.Describe(lyr.name)
if desc.dataType == "RasterLayer":
layers.add(desc.name)
self.params[0].filter.list = sorted(layers)
self.params[0].values = sorted(layers)
return
Submodel that uses multivalue passed from main model with script tool.
Here is tool's output
Does anyone has explanation for this strange behavior? What I'm doing wrong?
I finally figured it out. Derived output parameter's property "Obtained from" had to be set to input parameter in script tool.
Script tool's parameters:
Display Name: Input Rasters, Data Type: String, Type: Required, Multivalue: Yes
Display Name: Output Rasters, Data Type: Any Value, Type: Derived, Multivalue: Yes, Obtained from: Input_Rasters
Script tool's script code: