Select to view content in your preferred language

How can I view a multivalue output parameter as several values in ModelBuilder?

751
7
05-11-2010 12:58 PM
AustinMilt
New Contributor III
Let's say I have a script tool that takes 1+ input rasters and outputs them with the same extent to a directory. The input rasters go in a multivalue Raster Layer and the output rasters go in a derived multivalue Raster Layer. In ModelBuilder, the output shows up, as expected, as a Raster Layer table. However, I want ModelBuilder to split the table into individual Raster Layers, one for each output (i.e. there should be a green oval for each output raster). I need the behavior to be like this because each of the multiple output rasters goes into a different tool or a different tool parameter in subsequent steps in the model. Is this possible?

Thanks!
0 Kudos
7 Replies
ShitijMehta
Esri Regular Contributor
If you are working with 9.3 or 9.3.1 try using the variable of type list or series. List of inputs will all run together and create a list of individual outputs. The individual outputs will have to use %i% in the output name as in-line variable substitution.

Download this example and read help:
http://resources.esri.com/geoprocessing/index.cfm?fa=codeGalleryDetails&scriptID=15728


Read how to use lists, series and inline variable substitution:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Iteration_using_Lists
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Iteration_using_Series
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=In-line_variable_substitution

Hope it helps.
0 Kudos
AustinMilt
New Contributor III
If you are working with 9.3 or 9.3.1 try using the variable of type list or series. List of inputs will all run together and create a list of individual outputs. The individual outputs will have to use %i% in the output name as in-line variable substitution.

Download this example and read help:
http://resources.esri.com/geoprocessing/index.cfm?fa=codeGalleryDetails&scriptID=15728


Read how to use lists, series and inline variable substitution:
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Iteration_using_Lists
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Iteration_using_Series
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=In-line_variable_substitution

Hope it helps.


I've read on using the list/series variables to do what you suggest but have never actually tried it. While it is a solution, I'd rather not resort to it. I would think it a simple and worthwhile task to split a multivalue output variable into several several variables, but maybe ESRI hadn't thought of doing so yet?
0 Kudos
DaleHoneycutt
Regular Contributor
Unfortunately, the number of variables a tool outputs is fixed -- they are part of the tool signature.  There is no tool (or tool you can create) that dynamically creates some unknown number of outputs.  Iteration with lists/series is probably your best bet.  The only other thing I can think of is a hack -- create a script tool that outputs a known number of rasters -- a sufficiently large number of variables to handle whatever multivalue input you give it, then populate each output raster.  In Python, it would be something like this:

in_multivalue = gp.getparameterastext(0)
rasters = in_multivalue.split(";")
i = 1
for raster in rasters:
  gp.setparameterastext(i, raster)
  i = i + 1
0 Kudos
AustinMilt
New Contributor III
Unfortunately, the number of variables a tool outputs is fixed -- they are part of the tool signature.  There is no tool (or tool you can create) that dynamically creates some unknown number of outputs.  Iteration with lists/series is probably your best bet.  The only other thing I can think of is a hack -- create a script tool that outputs a known number of rasters -- a sufficiently large number of variables to handle whatever multivalue input you give it, then populate each output raster.  In Python, it would be something like this:

in_multivalue = gp.getparameterastext(0)
rasters = in_multivalue.split(";")
i = 1
for raster in rasters:
  gp.setparameterastext(i, raster)
  i = i + 1


I am OK with this approach as long as I can control which output variables are visible in ModelBuilder. For instance, if the user supplies 3 rasters for the tool, 3 green ovals will show up as the tool's output (instead of 3 green ovals and 37 white ovals). This way the user gets a less messy model. Is this possible?
0 Kudos
DaleHoneycutt
Regular Contributor
I am OK with this approach as long as I can control which output variables are visible in ModelBuilder. For instance, if the user supplies 3 rasters for the tool, 3 green ovals will show up as the tool's output (instead of 3 green ovals and 37 white ovals). This way the user gets a less messy model. Is this possible?


No -- not possible
0 Kudos
AustinMilt
New Contributor III
No -- not possible


Can't say I'm surprised to be let down again. I guess I'll go with the list/series option. Thanks for your help.
0 Kudos
AustinMilt
New Contributor III
I tried shitijmehta's suggestion to no avail. I needed to recombine outputs from the list/series processes and use them in a single tool at the same time. I did however devise an alternative, which I'm happy enough with to use. The basic idea is to take a multivalue raster variable and split it into individual outputs (which is what I wanted in the first place). The downside to my approach is the user has to do it himself in ModelBuilder.

The strategy is:

1. Create a script with these 3 lines of code:

import arcgisscripting
gp = arcgisscripting.create()
gp.SetParameterAsText(2,gp.GetParameterAsText(1))


2. Create a script tool with the script from #1 as the input script and these parameters:

  • name: whatever, data  type: any value, default everything else

  • name: whatever1, data type: string, multivalue: yes, default others

  • name: output, data type: raster dataset (or whatever type you need), type: derived, default everything else


3. The Tool Validator script should read:

class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup the Geoprocessor and the list of tool parameters."""
    import arcgisscripting as ARC
    self.GP = ARC.create(9.3)
    self.params = self.GP.getparameterinfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    
    self.params[1].Enabled = False
    self.params[1].Filter.List = []
    
    return

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""

    if self.params[0].Altered:
      self.params[1].Enabled = True
      self.params[1].Filter.List = str(self.params[0].Value).replace("'",'').split(';')

    if self.params[1].Altered:
      self.params[2].Value = str(self.params[1].Value)
      
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return


4. In Model Builder, add the above script tool and select your multivalue output from another process and the output you want to use as a raster in the following steps. You can do this for as many outputs from the multivalue output as you need.

Hope this helps someone
0 Kudos