Introduction to ModelBuilder

ModelBuilder is a visual programming language in ArcGIS Pro that allows you use a graphical editor to create custom tools that allow you to automate complex, tedious, or repetitive tasks where there are consistent step-by-step workflow sequences of operations.

Using ModelBuilder, you graphically chain together sequences of tools from the toolbox.

Advantages:

Disadvantages:

This tutorial demonstrates the basic use of ModelBuilder to automate simple workflows.

Workflows

A workflow is "the sequence of steps involved in moving from the beginning to the end of a working process" (Merriam-Webster 2023).

ModelBuilder might be better called WorkflowBuilder since what you are usually creating in ModelBuilder are automated workflows for complex sequences of processing tasks rather than models that are analytical representations of real-world phenomena.

ModelBuilder allows you to transform conceptual workflows into sequences of tool operations while also documenting those workflows as diagrams that facilitate communication of information about those workflows with non-technical audiences.

Workflows can be expressed in text as a sequence of steps. For example, this is the workflow for the address selection example given below:

Creating a ModelBuilder Diagram

To start the ModelBuilder editor, on the Analysis ribbon, select ModelBuilder.

To add a tool, on the View ribbon, select Geoprocessing, search for the tools and drag them into ModelBuilder. Tools are represented in model builder as rectangles and data is represented with ovals.

Creating a ModelBuilder diagram

View Python

Behind the scenes, ModelBuilder creates Python code that you can view.

On the ModelBuilder ribbon, click the Export options (green arrow) and select Send To Python Window to view or copy the code.

Viewing ModelBuilder Python code

Saving Diagrams

ModelBuilder diagrams are kept in a toolbox that you can view in the Catalog pane.

ModelBuilder diagrams must be explicitly saved using the Save button on the ModelBuilder ribbon.

You must save your diagram before saving your project or saving a project package, or your diagram may be missing some or all components when you reopen the project or project package.

Saving diagrams

Example Spatial Aggregation: Power Plants

This example demonstrates spatial aggregation (spatial join) by using power plant data to calculate per-capita coal-fired power plant generating capacity by state.

The power plant data is originally from the Energy Information Administration, and the state polygons are originally from the US Census Bureau. Both data sets are publicly available through the University of Illinois ArcGIS Online organization and can be directly loaded into ArcGIS Pro without having to go through a download / unzip process needed with shapefiles.

ModelBuilder Diagram

The following is the sequence of tools in this example:

Creating a ModelBuilder diagram to calculate per-capita coal generation by state

Map and Layout

Unless you set an output feature class to Add to Display, the ModelBuilder run will not change your map. Since ModelBuilder cannot change map symbology, you have to style the map manually anyway.

  1. Add the new feature class to a map.
  2. Style the map symbology.
  3. Insert a new figure layout (6 x 4).
  4. Add map frame.
  5. Hide the base map service credits.
  6. Add and format the legend.
  7. Export to PNG (Power_States.png).
  8. Import into Word.
  9. Rename the model, map, and layout (Power_States) in case you add additional items and need to be able to keep track of what goes with what.
Map and layout

Example Spatial Selection: Construction

This example demonstrates spatial selection in a scenario where you want to select address points around planned street construction in order to inform residents and businesses about potential traffic disruptions.

Feature Service Endpoints

The data used in this example will be address points and street centerlines from the Lake County, Illinois Open Data and Records Hub https://data-lakecountyil.opendata.arcgis.com/.

Because these data sets are large, this example will access this data using feature services provided on the hub page. This data is also available as zipped shapefiles in case you need a fixed snapshot of the data.

To use these endpoint URLs in the tools below, you will need to remove the query strings.

The endpoint URL provided by the data portal will look something like this:

https://services3.arcgis.com/HESxeTbDliKKvec2/arcgis/rest/services/LakeCounty_Transportation/FeatureServer/1/query?outFields=*&where=1%3D1

When you remove the query information, it should look something like this:

https://services3.arcgis.com/HESxeTbDliKKvec2/arcgis/rest/services/LakeCounty_Transportation/FeatureServer/1/
Finding Lake County endpoints

ModelBuilder Diagram

The following is the sequence of tools in this example:

Creating the diagram

Map and Layout

Unfortunately, ModelBuilder does not provide the ability to create new maps or layouts, and does not provide the ability automate map or layout formatting. You will need to symbolize and lay out the map manually.

Symbolizing the map and exporting the layout

Diagram Export

ModelBuilder diagrams can be exported to SVG and PDF files. Unfortunately, neither of those formats can be directly imported into Word documents.

The closest workaround is to take a screenshot of the diagram (using the PrtScr button on your keyboard), paste it into the document, and then crop to show only the diagram. The diagram will be fuzzy when printed, and getting a better quality document involves doing a conversion from SVG or PDF into PNG using an external program.

Exporting a ModelBuilder diagram to Word

Project Packages

ModelBuilder uses a toolbox that must be included in your project package if you want to be able to use this diagram on a different machine.

Make sure to check both share outside organization and include toolboxes when sharing a project package or the packaging may fail with an unhelpful failure message.

By default, data sets used or created in modelbuilder will be packaged in the project package. For feature services with large amounts of data (like the street centerlines and address points above) this will require significant time to package and upload.

include toolboxes when sharing a project package

Error 001659: consolidating toolbox

Error 001659: consolidating toolbox can occur when the project package contains large data sets, like the Lake County address points and street centerlines.

The workaround is to Save package to file and then upload the package file (.ppkx) to ArcGIS Online through your My Content page in a browser.

 \\192.168.100.3\DeptUsers\minn2\Documents\ArcGIS\Projects\Model Builder\Model Builder.atbx	

Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: Successfully wrote sharing info file	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: Creating thumbnail from map	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: About to start the external packaging process	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: Pending	StatusMessage: Sharing process started	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: Sharing process started	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: Reading thumbnail from file	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:39	Status: InProgress	StatusMessage: Packaging in progress	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:40	Status: InProgress
	StatusMessage: Creating a project package and uploading it to the portal	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:40	Status: InProgress	StatusMessage: Compiling packaging parameters	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:40	Status: InProgress	StatusMessage: Initiating the packager	
Model_Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 21:49:40	Status: InProgress	StatusMessage: The project package tool has started	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 22:01:27	Status: Failed	
	ErrorMessage: ERROR 001659: Consolidating toolbox 
	\\192.168.100.3\DeptUsers\minn2\Documents\ArcGIS\Projects\Model Builder\Model Builder.atbx	
Model Builder.ppkx		176	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 22:01:29	Status: Failed	ErrorMessage: Failed to package.

General Function Failure

The General Function Failure seems to occur if you share a project package without saving the diagram from the ModelBuilder ribbon with the Save button.

In some cases you might also need to completely close and restart ArcGIS Pro, reopen the project, and try sharing the package again.

It may also be necessary to close the ModelBuilder diagram before sharing.

Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: InProgress	StatusMessage: Successfully wrote sharing info file	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: InProgress	StatusMessage: Creating thumbnail from map	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: InProgress	StatusMessage: About to start the external packaging process	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: Pending	StatusMessage: Sharing process started	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: InProgress	StatusMessage: Sharing process started	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:08	Status: InProgress	StatusMessage: Reading thumbnail from file	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:09	Status: InProgress	StatusMessage: Packaging in progress	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:09	Status: InProgress	StatusMessage: Creating a project package and uploading it to the portal	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:09	Status: InProgress	StatusMessage: Compiling packaging parameters	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:09	Status: InProgress	StatusMessage: Initiating the packager	
Model_Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:09	Status: InProgress	StatusMessage: The project package tool has started	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:16	Status: Failed	ErrorMessage: General function failure	
Model Builder.ppkx		178	ProjectPackage	University of Illinois	
	https://univofillinois.maps.arcgis.com/	minn2@illinois.edu_UnivofIllinois_1190444167	
	2022-10-23 23:08:18	Status: Failed	ErrorMessage: Failed to package.

Database Not Found

The cryptic the database was not found packaging failure message apparently occurs because the feature classes created by modelbuilder are placed in the toolbox geodatabase rather than the project geodatabase.

If the Include Toolboxes option is not checked. the ModelBuilder toolbox (and its database) are not included in the project, share outside organization cannot include all feature classes used in project maps, and the packaging fails.

\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage				
	2022-10-23 20:38:26	status: inprogress	statusmessage: successfully wrote sharing info file	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage					2022-10-23 20:38:26	status: inprogress	statusmessage: creating thumbnail from map	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:26	status: inprogress	statusmessage: about to start the external packaging process	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:26	status: pending	statusmessage: sharing process started	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:26	status: inprogress	statusmessage: sharing process started	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:26	status: inprogress	statusmessage: reading thumbnail from file	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:26	status: inprogress	statusmessage: packaging in progress	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:28	status: inprogress	statusmessage: creating a project package and saving it locally	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:28	status: inprogress	statusmessage: compiling packaging parameters	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:28	status: inprogress	statusmessage: initiating the packager	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:28	status: inprogress	statusmessage: the project package tool has started	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:40	status: failed	errormessage: the database was not found.	
\\192.168.100.3\deptusers\minn2\documents\arcgis\model builder.ppkx		173	projectpackage
	2022-10-23 20:38:42	status: failed	errormessage: failed to package.	

Debugging Packaging Errors

Creating the package with ArcPy using arcpy.management.ProjectPackage() is touted as a debugging technique, but the output about missing tools is equally cryptic.

arcpy.management.PackageProject('\\\\192.168.100.3\\DeptUsers\\minn2\\Documents\\ArcGIS\\Projects\\Model Builder\\Model Builder.aprx', 'temp.ppkx')

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 12554, in PackageProject
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 12551, in PackageProject
    retval = convertArcObjectToPythonObject(gp.PackageProject_management(*gp_fixargs((in_project, output_file, sharing_internal, package_as_template, extent, apply_extent_to_arcsde, additional_files, summary, tags, version, include_toolboxes, include_history_items, read_only, select_related_rows, preserve_sqlite), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in 
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 002700: At version 2.2 the "ExportFeatures (conversion)" tool is not available
 ERROR 003498: At version 2.2 the "SelectLayerByLocation (management)" tool's "Input Features" parameter's multiValue has changed
Failed to execute (PackageProject).