ArcMap

Generating a multivalue choice list

Prerequisite Reading
Generating a choice list from a field

This blog is an extension of the blog Generating a choice list from a field, explaining:

How to create a MULTIVALUE parameter choice list from an input feature class/table automatically. In this example, multiple input parameters from a choice list are then iterated through.  The model can be easily extended to carry out numerous analysis that require user selected input parameters.

Data
Download the data from here.

Understanding the model:

  1. Download an example script tool from here.
  2. Add the script tool to the model.
  3. Expose the input parameters (input feature class, field, value) of the script tool in the model.
  4. Make the input parameters model parameter.
  5. Use as described in the example below:

In the following example, the user can define an input feature class (e.g.Bird Locations) and a field (e.g. Type) to generate a value list, from the model tool dialog. The value list parameter is then populated with a choice list of all the unique values in the field. This list is a multivalue parameter i.e. you can select multiple values from the drop down list.

The output of the script tool is the multivalue with all the selected value (e.g. American Coot, Black Scoter, Canada Goose and Gadwall). In the model provided, this multivalue output is then connected to the Multivalue Iterator as input in the sub-model. Learn more about model within a model/sub-model.

The tool then iterates over each value (e.g. American Coot, Black Scoter, Canada Goose and Gadwall). The output of this iterator (Values variable) is then input to the Select tool as an inline variable, in the expression, to select features (Type” = ‘%Value%’). Learn more about inline variable substitution.

The Calculate Value tool is used to remove spaces in the selected values (e.g. American Coot changes to AmericanCoot (no space)) using the .replace Python function.

The output of the Calculate Value tool is then used as inline variable in the output of the Select tool (e.g. C:ScratchScratch.gdb%Name%).

The Collect Value tool is used to collect the output from all the iterations. The output of the Collect Value tool is made a model parameter so that when the sub-model is added to the main model, the output of model parameter becomes a variable in the model.

To run the iterator and the Calculate Value tool before the Select tool two preconditions are created:

  1. From the output of the iterator to the Select tool.
  2. From the output of the Calculate tool to the Select tool.

Tips:

**************IMPORTANT NOTE**************

Understanding the tool
Prerequisite reading – Read more about the tool and the validation code for the tool from here.

To make this script tool parameters a multivalue parameter, the script tool property for the Value and Output value parameters have been changed as shown below:

The script tool validation code can be accessed by right clicking the script tool > selecting Properties > Validation tab > and clicking the Edit button. This opens the validation code in the Python editor for better viewing. The code has added comments explaining the code on each line.

Next Article

PerfTools (Build 122) for ArcGIS Pro 2.x is now available for download

Read this article