Integrating a model within a model

Model tools are fully integrated into the geoprocessing framework and can be used in the same way all system or script tools can. Like all other geoprocessing tools, model tools can be executed from a dialog box, through Python scripting, or added and run in another model.

The idea of adding and running one model tool within another model is sometimes referred to as a submodel, nested model, or model within a model. There are two main reasons for using this type of model hierarchy: to simplify a large, complex model or allow for more advanced use of model iterators.

Simplifying a large, complex model

Embedding a model tool within another model allows for large, complex processes to be divided into smaller model units that can be better managed and easily reused in other models or scripts. These submodels can also be modified and rerun without the need for rerunning the entire process—if an error occurs in one submodel, make corrections to only that model, then rerun the single model instead of having to run the entire process again.

Breaking a big model into smaller sub-models
One large model that could be broken into four submodels and one main model

The large model above could be broken into four submodels and one main model. The smaller submodels can be added to a main model and connected to a final process. When a submodel is added to another model, the submodel's final output will be added as an output variable.

Adding Sub-Models to Main Model

Advanced use of model iterators

Embedding a model tool within another model also allows a more advanced use of model iterators. When a workflow requires model iteration, the specific tools or processes that need to be run more than once must be separated from those tools or processes that only need to be run once per workflow. In this situation, all tools that need to run multiple times should be placed in one model with a model iterator and used as a submodel. The tools that only need to be run once should be placed in the main model, which calls the iterating submodel.

The example below is an automated workflow that merges a set of inputs from a geodatabase. The Merge tool accepts multiple feature classes as input to merge, but there is no automatic way to add all feature classes from a specific workspace. In this situation, the Iterate Feature Classes model iterator can be used in combination with the Collect Values tool to read through all the feature classes in a workspace and collect all them into a single variable. Since these two processes need to be executed multiple times (iterations), they will be added to a submodel, while the Merge tool, which should only be executed once, will be added to the main model and connected to the output of the Iterate Feature Classes/Collect Values submodel.

Main and sub model

The following is a step-by-step description of how the full workflow above was created. Refer to Essential ModelBuilder vocabulary for more information about terms and techniques used below.

Steps:
  1. Create two models: a main model and a submodel, where the submodel is nested inside the main model. Add the Merge tool to the main model and the Iterate Feature Classes iterator and the Collect Values tool to the submodel.
  2. In the submodel, set the workspace containing the feature classes to be merged as the input for the Iterate Feature Classes iterator. To only iterate through point feature classes, set the Feature Type parameter of Iterate Feature Classes to POINT.
    Setting iterator
  3. Connect the Iterate Feature Classes output variable Output Feature Class to the Collect Values tool, so the path of every point feature class in the workspace is iterated through and collected.
  4. Make the input workspace variable and the output of the Collect Values tool into model parameters. Rename the input workspace variable Input Dataset to ensure that the variable name is relevant and easy to understand.
    Setting Sub-model
  5. Save and close the submodel, then add it as a process to the main model.
  6. When the submodel is added to the main model, the submodel's parameters are automatically added as variables in the main model.
    Adding Sub-model
  7. Set the output variable of the submodel as the Input Datasets of the Merge tool. Make sure the Merge tool output has a valid path.
  8. Rename the input variable of the submodel Input Dataset and the output variable of the Merge tool Merge Output. Set both the Input Dataset and Merge Output variables as model parameters.
    Nested model

9/13/2011