Creating a simple model

This section takes you step-by-step through creating and running a new working model. The model merely creates a new database table and adds a field. You don't need any data to complete this example, other than a folder on disk. The purpose behind the simplicity of this model is to demonstrate the essential key concepts of model building, rather than to demonstrate geographic concepts.

The first task is to create a custom toolbox to contain the example model. Start ArcCatalog, open the ArcToolbox window, and create a new toolbox. Name this toolbox Simple Model Example (in practice, the name doesn't matter).

Learn more about creating a custom toolbox

The next step is to create a new model. Right-click the Simple Model Example toolbox and click New > Model. The ModelBuilder window will open and the diagram area will be empty.

Next, locate the Create Table tool in the ArcToolbox window. It can be found in Data Management tools > Table toolset.

Learn more about locating tools in ArcToolbox

Drag and drop the Create Table tool onto the ModelBuilder diagram. The ModelBuilder window should now look as follows:

Creating a model 1

Double-click the Create Table tool to open its dialog (or right-click and click Open). You only need to provide the two required parameters as shown below: an output location (in this case a folder named E:\OutputFolder—you can use any folder on your system) and an output table name. Use SimpleTable.dbf for the output table name. After filling out these two parameters, click OK.

Creating a model 2

The model should now appear as shown below. The blue oval represents input data, and the green oval represents output data. Notice that the label on the output table has its text wrapped and is difficult to read. You can resize the oval by clicking it to show its blue resize handles. Click and hold a resize handle and drag your mouse to resize. If you click in the center of the oval and drag the mouse, you can reposition the oval anywhere on the ModelBuilder diagram area.

Creating a model 3

After resizing, the model is now more readable.

Create a model 4

At this point, nothing has happened since you haven't executed the model—SimpleTable.dbf does not yet exist on disk. The reason is that in ModelBuilder, when you open a tool dialog in and click OK, you are returned to the ModelBuilder window; the tool does not execute. This is different behavior than opening the tool from the ArcToolbox window and clicking OK, which does cause the tool to execute.

The next step is to add a new field to SimpleTable.dbf. Locate the Add Field tool in the ArcToolbox window, which is found in Data Management tools > Fields toolset. Drag and drop the Add Field tool onto the diagram area as shown below.

Creating a model 5

Double-click the Add Field tool in ModelBuilder to open its dialog. For the Input Table parameter, reveal the drop-down list and choose the SimpleTable.dbf entry. The icon next to SimpleTable.dbf (shown below) means that the input data is a variable in the model. You'll learn more about variables later.

Choosing model data

For the field name, type "Table_ID". For the rest of the parameters, use the default values. Click OK to close the dialog. Your model should now look as follows:

Creating a model 7

Note how the output of Create Table is connected as the input to Add Field. The output of Add Field is SimpleTable.dbf (2), a name that was automatically generated by ModelBuilder.

There is something interesting going on here. If you open the Add Field tool dialog, you'll note that none of the parameters asks you for an output table name. That's because the field will be added to the input table, so it's not necessary for the tool to have an output table parameter. Yet in ModelBuilder, there is an output—SimpleTable.dbf (2). This output contains the new field that will be added by the Add Field tool when the model is executed. The reason is that in ModelBuilder, all tools must produce an output so you can connect the output to another tool. For example, if you needed to add another field, you could add another Add Field tool and choose SimpleTable.dbf (2) as input, which would produce SimpleTable.dbf (3) as output. In this manner, you could string together as many Add Fields as you needed.

The model is now ready to run. You can run the model from the ModelBuilder window by clicking the Run button Run model tool or clicking Run from the Model menu. After you run the model, the tools and data should have shadow boxes as shown below, signifying that the tools have been executed and the data has been created.

Model after running from within ModelBuilder

You can also execute the model by opening it in ArcToolbox. First save the model by clicking the Model > Save menu command, then the Model > Close menu command, as shown below.

Model menu

In the ArcToolbox window, locate the Simple Model Example toolbox you created. The model you just created will be named Model, as shown below.

Model in ArcToolbox

Double-click Model to open its dialog. It should appear as below.

Creating a model 8

The message, This tool has no parameters, is not an error. It simply means that the model has all the information it needs to execute, in this case, the output folder, table name, and field name. Click OK to execute the model. The progress dialog will appear and you will see messages written by both the Create Table tool and the Add Field tool. Once the model executes, you can navigate to SimpleTable.dbf in ArcCatalog and view its properties. There should be three fields: OID, Field1, and Table_ID. The first two fields are always created by the Create Table tool. See the section Create Table fields below for more information on these two fields.

Creating and exposing parameters

You can edit the model you just created so that when it is opened, the user can choose a table name.

The first step is to open the ModelBuilder window. In ArcToolbox, right-click the saved model tool and click Edit. This will open the ModelBuilder window and the diagram contains your model.

In the next step, you are going to make a model variable for the output table to be created then expose it as a model parameter.

Right-click the Create Table tool, point to Make Variable > From Parameter, then click Output Table, as shown below.

Making a parameter

A light blue oval should appear with the label Output Table. This oval will probably appear on top of the OutputFolder oval, so you'll need to reposition it by clicking and dragging the Output Table oval.

Next, right-click Output Table and click Model Parameter, as shown below.

Creating a model 9

The Output Table oval should now have the letter P beside it to signify that it is a model parameter, as shown below.

Creating a model 10

Save and close the ModelBuilder window as before, and double-click the model tool to open its dialog. It should now look as follows:

Creating a model 10

The Output Table parameter is filled in with SimpleTable.dbf because the model still contains SimpleTable.dbf as the value for the Output Table variable.

The warning icon appears since you previously ran the model and the output SimpleTable.dbf exists.

Having the Output Table parameter preset to SimpleTable.dbf is the same as having a default value for the parameter, which might be awkward in some situations where you want users of this tool to be required to enter an Output Table value, rather than letting them accept a default.

To remove SimpleTable.dbf as the default value, edit the tool to open the ModelBuilder window. Double-click the Output Table oval to open the parameter control and delete the text SimpleTable.dbf. Click OK and your model should now appear as follows:

Creating a model 11

All the data elements and variables (the ovals), except OutputFolder, are white, meaning they are empty. All the tools are also white, meaning they don't have enough information to execute. If you now run the model from the ModelBuilder window, you will get the message "None of the processes are ready to run". However, if you execute the model tool from ArcToolbox and supply the name of the output table, the tool will execute.

Note that the names of the output data, SimpleTable.dbf and SimpleTable.dbf (2), have not been changed. This is not a problem—when the tool is run, the actual table name created will be the name that the user supplies. In the model, SimpleTable.dbf and SimpleTable.dbf (2) are simply labels, not the actual names of the output.

Learn more about element labels in models

Save and close the model as before, then double-click the model tool to open the dialog. The Output Table parameter will now be empty.

Creating a model 12

You can now provide another name for the table. It will be created in the output location and will contain the Table_ID field.

Create Table fields

When you execute this example model, the table you create will actually contain three fields: OID, Field1, and Table_ID. (Be sure that the name of the table you create has a suffix of .dbf. If you don't append this suffix, an INFO table will be created, with the fields: Rowid, OBJECTID, FIELD1, and TABLE_ID).

The OID and Field1 fields are automatically generated by the Create Table tool. The Create Table tool has to create a valid ArcGIS table, which means the table has to have an Object Identifier field (OID), which is used exclusively by ArcGIS, and at least one user field (Field1). The Create Table tool doesn't know if you're going to add fields to it, so it has to always add these fields to make a valid table. Fields that Create Table adds depends on the type of table created (INFO, dbf, or geodatabase).

Knowing this behavior of the Create Table tool, you can account for it in your model by adding the Delete Field tool to delete Field1. Using the same techniques as before, drag and drop the Delete Field tool into your model, double-click the Delete Field tool, then choose SimpleTable.dbf (2) as your input. The model should look as follows.

Adding Delete Field to the model

Open the Delete Field tool. In the Drop Field parameter control, click Add Field to add a new field and rename it Field1, as shown below.

Using the Delete Field tool

When you execute this model, the output table should have only two fields, OID and Table_ID.

Conclusions and key points

This simple model example demonstrates some key concepts about model building:

See Also