A quick tour of creating tools with ModelBuilder

The scenario for the model illustrated below is that you're assembling data for a specific study area, represented by the StudyArea variable in the model, and you need to clip several datasets to the study area. For each dataset you clip, you want to add a field named STATUS and calculate the field to the initial value of 1. In reality, you may want to add several fields and calculate their values, but for this simple scenario, the STATUS field is all that is needed.

The model below performs the work of clipping, adding a field, and calculating the field, but the data you need to assemble is spread across several map documents and geodatabases. The workflow issue you face is that every time you want to run the model, you have to open the model in ModelBuilder and change the input to Clip from Soils to another dataset.

Example model

Rather than opening ModelBuilder each time you want to process your dataset, wouldn't it be better if you could run the model using its tool dialog box, supplying the name of the input dataset by dragging a layer or dataset onto the dialog box, just as you would with a system tool? But when you open the tool dialog box, it displays This tool has no parameters, as illustrated below, so there is no way for you to enter the datasets you want to process.

Model Tool dialog

Another issue with the model is that you cannot use it in another model. The illustration below shows adding the tool to a new model with the intent of connecting the output of the model to the Identity tool. A connection cannot be made because the Clip to study area and add field tool has no output that can be connected to the Identity tool.

The model tool cannot be used in another model because it has no output parameters

The solution—Create model parameters

Both the above situations can be solved by creating model parameters. To create a model parameter, you right-click a model variable and choose Model Parameter. In the illustration below, the Soils and Soils_Clip (3) variables have been made model parameters. Model parameters are shown with the letter P next to the variable.

Model with model parameter variables

Now when the model tool dialog box is opened, you can change the Soils parameter to something else, such as a vegetation dataset or layer. You can also supply a different output dataset name. When you click OK, the tool will run using the data you provide.

Tool dialog showing parameters

Note that the model variable StudyArea was not made a parameter. Since the study area never changes, it is not necessary to make it a parameter.

Dive-inDive-in:
In this model, the StudyArea variable contains a dataset (D:\EastValley\Data\collect.gdb\studyarea) rather than a layer name. If the StudyArea variable contained a layer name, the tool would not execute in the background; you would need to turn background processing off, as described in Foreground and background processing.

Changing parameter names

There's one problem with the tool dialog box—the parameter names are not very descriptive; instead of the parameter names of Soils and Soils_Clip (3), you want something more descriptive, such as Input Features and Output Feature Class. To change the parameter names on the tool dialog box, you change the names of the variables in ModelBuilder, as illustrated below.

Model with renamed parameters

Now when you open the tool dialog box, the parameter names make sense:

Tool dialog with renamed parameters

Making parameters blank

Finally, notice that the parameters in the tool dialog box are prepopulated with values, in this case Soils and E:\10DocModels\PortlandSmall.gdb\Soils_Clip. If you open the tool in ArcMap and there is not a layer named Soils, the dialog box will display an error (a red X) because the layer Soils does not exist. While this is not an issue—you can always select another layer or browse to another dataset—you can avoid the nuisance of the error message by clearing out the variables in the model, as illustrated below. The model will no longer run in ModelBuilder, but it will run using its tool dialog box.

Model with empty variables

Now with the model variables empty, the tool dialog box no longer displays values.

Tool dialog with empty values for the parameters

Using the model tool in another model

Now that the model has parameters, you can add it to ModelBuilder and connect its output to the input of Identity, as illustrated below.

Using a model within a model.

Summary

To make your model a usable tool, you create model parameters. Model parameters appear on the tool dialog box. The name of the model variable becomes the parameter name in the tool dialog box. You don't have to make every model variable a model parameter; in the example above, the StudyArea variable is not a model parameter because it never needs to change.

Creating model parameters allows you to turn your model into a useful tool—you can use the tool with different data, you can add it to other models, and use it in scripts. Over time, you'll build up your own library of useful tools and use them in situations you never anticipated when you first created the model. Just as importantly, you can break large complex models into smaller (and therefore more manageable) models, feeding the output of one tool into the input of another tool.

To learn more about creating model tools, see the Creating tools with ModelBuilder tutorial.


4/14/2011