Work with a model within a model

Summary

Create a model within a model, or a nested model. The model iterates over a few feature classes, projects them, and merges them to create a single feature class.

Finished model

A nested model is required when part of a model does not need to run multiple times. If an iterator is added to a model, all tools in that model are run for each value the iterator returns. In this example, you'll iterate the Project tool for each feature class; however, running the Merge tool multiple times does not make sense, as it takes all the projected feature classes together and creates a merged output by running only once. Therefore, the Merge tool is added to a main model that runs once and calls a submodel that runs more than once.

Prerequisites

If you are new to ModelBuilder, review the following topics:

Open the project

Download the project to use in this workflow. The project includes input data, an output geodatabase, and a completed model.

  1. Open the Work with Model Within A Model overview page.
  2. Click Download on the right side of the page.
  3. Right-click the downloaded ModelWithinModel.zip file and extract it to a convenient location, such as C:\Temp.
  4. In the extracted folder, ModelWithinModel, double-click the ArcGIS Pro project file, ModelWithinModel.aprx.
  5. Explore the data in the Catalog pane, and click the Project tab if necessary. Browse to Folders > ModelWithinModel.

    The ToolData.gdb geodatabase contains three feature classes that will be used as inputs for the model.

    The outputs of the model will be written to the ScratchCommon.gdb geodatabase.

Add tools

You'll create a model in the MyProjectTools toolbox. To add tools to the model, complete the following steps:

  1. In the Catalog pane, click the Project tab. Browse to Folders > ModelWithinModel > MyProjectTools.
  2. Right-click MyProjectTools and click New. Select Model to create and open a model.
  3. On the ribbon, click the ModelBuilder tab. In the Model group, click Properties Properties. On the Tool Properties dialog box, type ProjectMainModel for Name and Project Main-Model for Label.
  4. On the ribbon, under the ModelBuilder tab, in the Model group, click the Save button Save to save your changes.
  5. Create another model with the Name of ProjectSubModel and the Label of Project Sub-Model.
  6. In the Project Sub-Model model, add the Iterate Feature Classes tool.
    1. On the ribbon, click the ModelBuilder tab.
    2. In the Insert group, click Iterators Iterators.
    3. In the Iterators list, click Iterate Feature Classes.

    Adding the Iterate Feature Classes tool

    The Iterate Feature Classes tool is added to the Project Sub-Model model. The iterator is unavailable since no parameter values have been provided.

  7. Add the Collect Values tool.
    1. On the ribbon, click the ModelBuilder tab.
    2. In the Insert group, click Utilities Utilities.
    3. In the Utilities list, click the Collect Values tool.

    Adding the Collect Values tool

    The Collect Values tool is added to the Project Sub-Model model.

  8. Add the Project tool.
    1. Click in the model, and type Project directly in the model to open the Add Tools To Model dialog box.
    2. Search for the Project tool.
    3. Double-click the Project tool and add it to the model.

Specify the tool parameters and connect the tools

After adding tools to the model, you need to specify the parameters for each tool.

  1. Double-click the Iterate Feature Classes tool to open the iterator's dialog box.
    1. For the Workspace or Feature Dataset parameter, browse to the ToolData.gdb geodatabase.
    2. Keep the default values for the remaining parameters, and click OK.

    Iterate Feature Classes tool dialog box

    The workspace is added as a model variable to the model (dark blue oval) and the color of the iterator changes, indicating that the required parameters have been supplied and it is ready to run.

  2. Right-click the output of the iterator and click Rename. Type Feature Class for the name.
  3. Double-click the Project tool to open the tool's dialog box.
    1. For the Input Dataset or Feature Class parameter, choose Feature Class from the drop-down list.
    2. For the Output Dataset or Feature Class parameter, browse to <Your Project Location>\ScratchCommon.gdb and type %Name%_Projected.
    3. For the Output Coordinate System parameter, select Projected Coordinate System > State Plane > NAD 1983 (Meters) > NAD 1983 StatePlane Oregon North FIPS 3601 (Meters).
    4. Keep the default values for the remaining parameters, and click OK to close the Project tool dialog box.

    Project tool dialog box

    Caution:

    If your input feature classes have different coordinate systems, the geographic transformation may not apply to all and might project the data incorrectly. Be aware of your input coordinate systems and which geographic transformation methods applies to them. Use the iterator's Wildcard parameter to selectively project feature classes in such cases.

  4. Hover over the Project tool output variable (green oval). Click and drag to draw a connector line to the Collect Values tool. Release the mouse and click Input Value on the pop-up menu.

    The Collect Values tool is a model utility tool used to collect the output values of each iteration into a single multivalue output.

  5. Right-click the input variable to the iterator and check Parameter.

    This adds a letter P next to the variable, indicating that it is a model parameter.

  6. Create a model parameter from the output of the Collect Values tool in the same way you did above.
  7. To arrange the model elements, click the Auto Layout button Auto Layout on the ModelBuilder tab and click the Fit To Window button Fit To Window to maximize the layout to the size of your model window.
  8. Click the Save button Save on the ModelBuilder tab to save the model, and close the Project Sub-Model model.
  9. In the Project Main-Model model, search for the Merge tool and add it to the model.
  10. In the Catalog pane, browse to the Project Sub-Model model you just created. Drag the Project Sub-Model model into the Project Main-Model model.

    The submodel is added to the main model. The submodel parameters are added as variables to the main model (the dark blue oval for ToolData.gdb and the green oval for Output Values).

  11. Hover over the Project Sub-Model output variable Output Values (green oval). Click and drag to draw a connector line to the Merge tool. Release the mouse and click Input Datasets on the pop-up menu.

    This creates a connection between the submodel output and the Merge tool.

    Setting the Merge tool Input Datasets parameter

  12. Double-click the Merge tool to open the tool's dialog box. For the Output Dataset parameter, browse to <Your Project Location>\ScratchCommon.gdb geodatabase and type ProjectedFC_Merge. Leave the default value for the Field Map parameter and click OK to close the dialog box.

    Setting the Merge tool Output Dataset parameter

    It is good practice to rename the input and output variable names to more meaningful names instead of using the default variable names.

  13. Rename the Merge tool output Merged Feature Class. Rename all the other model variables as shown in the finished model of the workflow.

Run the model

You'll validate and run the model. You'll examine the outputs in the ScratchCommon.gdb geodatabase and confirm that all feature classes have been merged after projection.

  1. Right-click the output of the Merge tool, and click Add To Display.

    The outputs are added to the map.

  2. Click the Save button Save on the ModelBuilder tab to save the model.
  3. Click the Run button Run on the Project Main-Model tab to run the model.

    The model runs the submodel and iterates over all the feature classes, projects them, and creates the output in the ScratchCommon.gdb geodatabase. The Collect Values tool collects the outputs in the submodel and passes the datasets to the Input Datasets parameter of the Merge tool. The Merge tool runs once and creates a merged output.

    Output from a model within a model
  4. Close the model and ArcGIS Pro.