ArcGIS Blog

Analytics

ArcGIS Pro

Build Better Custom Geoprocessing tools (now with Enable Undo) in ArcGIS Pro!

By Margaret Crawford

banner image

Approximate reading time: 7 min

ArcGIS Pro Release: 3.4

Building custom tools in ArcGIS Pro gives you the opportunity to automate repetitive workflows or design tools that are tailored to your analysis. You can use ModelBuilder or Python to create tools inside custom toolboxes. And by designing and sharing your toolboxes, you enable others to benefit from your expertise with a customized tool to help them work more efficiently.

This blog explores some tips and new features in the latest releases for building custom tools, including:

•  Build custom tools–Learn how to build a custom script tool.

•  Document custom tools–Use the Tool Properties dialog box to document custom tools.

•  Attributes–Add an Enable Undo toggle and banner messages to custom tools.

•  Environments–Select a subset of environment settings your custom tool supports.

•  Parameter Controls–Use the controlCLSID property to set a custom tool parameter control.

Note: Much of this new functionality is only available for custom tools stored in the new ArcGIS toolbox (.atbx) format introduced in Pro 2.9. So, if you’re still using legacy toolboxes (.tbx), copy and paste your tools into a new toolbox for an enhanced experience.

Create a custom tool

ArcGIS Pro projects have a default toolbox that is automatically created and available in the Catalog and Geoprocessing panes.

Default Toolbox
Default toolbox in the Catalog (left) and Geoprocessing (right) panes.

You can also add other toolboxes including legacy toolboxes (.tbx) and Python toolboxes (.pyt) to your project or view toolboxes in your project folders or Favorites.

Similar to a new toolbox you’d buy at a hardware store, you should fill your Pro toolbox with useful tools, like custom script and model tools. Custom tools give you the power to automate and streamline both simple and complex workflows that string together sequences of geoprocessing tools.

For example, here is a custom script tool, Delete Features By Attribute, that deletes features based on a query. There are multiple ways to create this tool; you can use multiple geoprocessing tools in sequence, or you can use arcpy data access (da) cursors to delete records from a dataset.

 

Example of a custom script tool
Custom script tool: Delete Features by Attributes

You can create this script tool in a toolbox by following these steps:

1)  Right-click a toolbox, then select New > Script
This opens the Tool Properties dialog box, where you can set the tool’s general properties, parameters, execution and validation code, and environments.

2) On the General tab, provide the tool with a Name and Label.

3) All tools have parameters, which are the input and output values or conditions that define how a tool runs. On the Parameters tab, you can set the tool’s parameter properties in a grid. This custom tool has three parameters:

Label Name Data Type Type Direction Dependency
Input Feature Input_Feature Table View Required Input
Expression Expression SQL Expression Optional Input Input_Feature
Updated Feature Updated_Feature Table View Derived Output Input_Feature

Note: The tool needs a derived parameter with a dependency on the input parameter. This indicates the dataset specified as the input is updated by the tool’s code, and it allows the tool’s updated output to be chained to other tools in ModelBuilder.

4) If you were to try to run the tool at this point, it would not work. When someone clicks Run on the tool dialog box, the tool runs a script to process the parameter values. Open the Execution tab to see the script editor. Below is the tool’s execution code:

Use Tool Properties to Document Custom Tools

If you want to share your tools with other people, you should provide information, illustrations, and details about how the tool works. You can document custom tools in the Tool Properties dialog box or the tool metadata.

Over the past few releases, we’ve added and refined several features in the Tool Properties dialog box for documenting custom geoprocessing tools:

•  Use the General tab to set a Description, Summary, Illustration, and Icon for custom tools. The Description will display when you search for the tool, and the Summary and Illustration will display on the tool dialog box when you hover the tool help.

Tool Help
Tool Help in a custom tool dialog box

•  On the Parameters tab, click the Description button pencil on each parameter to set parameter descriptions. This content will display when you hover the information icon  next to the parameters on the tool dialog box.

Parameter Description
Parameter Description in a custom tool dialog box

Attribute Options: Enable Undo for Custom Tools

In ArcGIS Pro 3.4, custom tools have four new Attributes to control the tool’s user experience:

•  Show banner that tool modifies the input data

•  Do not add tool outputs to map

•  Show Enable Undo toggle

•  Show banner that tool consumes ArcGIS credits

For the Delete Features By Attribute example, I’ve checked the attributes: Show banner that tool modifies the input data and Show Enable Undo toggle.

Custom tool Attributes
Custom tool Attributes in the Tool Properties dialog box.

With these attributes set, a banner will display at the top of the tool dialog box, and the Enable Undo toggle will appear next to the Run button.

Custom tool with enable undo button.
You can add a banner message and the enable undo button to custom tools.

In the execution code, the script tool can either use the Delete Rows geoprocessing tool (commented out above) or the arcpy.da cursor to perform the edits. Depending on the method used, set the execution script as follows:

•  Geoprocessing tool–If a custom tool uses a geoprocessing tool to perform edits, no execution code changes are needed for the Enable Undo toggle to work.

•  arcpy.da cursor–If a script tool uses an arcpy.da cursor to perform edits, the tool’s execution code must contain the Editor class and the startEditing method to use edit sessions. Set the Editor class to the workspace containing the dataset being edited. When the code calls to the startEditing method, set the with_undo argument to True or leave it blank, so the edit can be undone after the tool runs.

Run your custom tool with Enable Undo
Run your custom tool with Enable Undo.

Environments

Tool environments are additional, optional settings that modify how a tool runs.

In ArcGIS Pro 3.3, the Environments tab was added to the Tool Properties dialog box so you can choose the environment settings supported by your custom tool and displayed in the tool environments. By default, all environments are listed as supported for custom tools. Choosing a subset of environments can make your custom tool more user-friendly. Instead of displaying all 40+ environment settings, you can display a few that are relevant to your custom tool

Set the custom tool Environments
The Environments tab in the Tool Properties and tool dialog boxes.

Customize Parameter Controls using the controlCLSID property

Parameters are like the control panel for your tools, where you set the inputs, outputs, fields, distances, or make other modifications to guide how users work with your tool. In custom script tools and Python toolbox tools, you can modify the interface of your parameter controls to potentially make your tools more interactive and easier to use.

Note: Parameter controls cannot be customized in model tools. Model parameters typically come from the geoprocessing tools inside the model, and the control is inherited from the original tool.

To modify a parameter control, you must set the controlCLSID property in the tool’s validation code with a value that is compatible with the parameters Data Type property.

Alternative controls are supported only by specific parameter data types. For example, say you have a tool with a parameter that uses a Double or Long data type with a defined minimum and maximum value (Range Filter).

Set a filter on a numeric parameter
Set a filter on a numeric parameter.

You can find which controls are compatible with numeric parameters, then use a slider bar control by specifying a controlCLSID value of {C8C46E43-3D27-4485-9B38-A49F3AC588D9}.

This provides a more visual and interactive way for users to select the parameter values in your custom tool.

slider bar control
Add a slider bar control to your custom tools

Summary

In ArcGIS Pro, you can create custom tools using Python or ModelBuilder, and you can use the Tool Properties dialog box to configure your tool’s properties. Over the past few releases, we’ve added more options to make it easier to document and design your custom tools. You can use Tool Properties to document your tools, set tool attributes, tool environments, and modify the parameter controls.

To see what else is new in ArcGIS Pro 3.4, please visit the What’s New documentation and post your questions in the ArcGIS Pro board in the Esri Community.

Share this article