Creating a simple model An update to the ArcGIS 9.2 Desktop Help files Related Topics An overview of models (from the 9.2 help files (so a little out of date as far as the user interface is concerned) but still provides a good overview of models) A whirlwind tour of geoprocessing with ModelBuilder This document 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 ArcMap and open the Catalog window. Right click in the Toolbox, My Toolbox directory and select New > Toolbox. This creates a new toolbox that will house our simple model. Name this toolbox Simple Model Example (in practice, the name doesn't matter). 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 either the Search or the ArcToolbox window. It can be found in Data Management tools > Table toolset. Drag and drop the Create Table tool onto the ModelBuilder diagram. The ModelBuilder window should now look as follows: 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. 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. After resizing, the model is now more readable. 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 and click OK, you are then 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. 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. 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: 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 or clicking Run from the Model menu. A new window will open and tell you if the model run was completed, or if errors were encountered. See below. Close the pop up box. After you run the model, you should also find that the tools and data now have shadow boxes as shown below, signifying that the tools have been executed and the data has been created. 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. In the ArcToolbox window, locate the Simple Model Example toolbox you created. The model you just created will be named Model, as shown below. If it isn’t in the Toolbox, simply find the toolbox you created in ArcCatalog and drag and drop it into Toolbox. Double-click Model to open its dialog. It should appear as below. 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 your model diagram. 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 Table Name, as shown below. 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. The Output Table oval should now have the letter P beside it to signify that it is a model parameter, as shown below. Save and close the ModelBuilder window as before, and double-click the model tool to open its dialog. It should now look as follows: 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: All the data elements and variables (the ovals), except the Output, 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. 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. 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. 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. The model should look as follows. 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: You create models in ModelBuilder. When you create a new model, ModelBuilder is opened automatically. To open ModelBuilder for an existing model tool, right-click the tool in ArcToolbox or ArcCatalog and click Edit. You can drag and drop tools from the ArcToolbox window. You can also drag and drop data from ArcCatalog. Tools are shown as rectangles, and data (both input and output) is shown as ovals. Lines connect data to tools, and the arrows show the direction of data flow (input or output). Tools and data are displayed in different colors, as described in Elements. Models have parameters, signified by the letter P next to the data. A model parameter means that the user will be able to supply a value for the parameter when the tool dialog is opened from ArcToolbox or ArcCatalog. All tools have output data, even if there is no output parameter in their tool dialog. The examples above using the Add Field tool demonstrates this; there is no output table parameter in the Add Field dialog, yet there is an output in ModelBuilder. This is to allow you to feed the output of one tool as input to another. The model you create is a tool in a toolbox and can be opened and executed like any other tool. The only difference is that you can edit a model tool. Since a model is a tool, you can drag and drop model tools into other models and use them in scripts.