This blog post examines the differences between custom toolboxes and Python toolboxes in ArcGIS Desktop.
ArcGIS Desktop enables you to create custom toolboxes and Python toolboxes. As both are related to Python scripting, their names might sound a little confusing. Let´s investigate how both compare to each other.
What is a custom toolbox and how are they created?
Python scripting can be used for running standalone scripts outside of ArcMap. As long as these scripts don´t require user input, this is a perfect solution. But this isn´t always the case: sometimes you want a script to run inside of ArcMap and accept user input, such as the opportunity to select a feature class. This is where custom toolboxes and script tools come into play.
The most important part is a script tool: a Python script that has been transformed into a toolbox that can be run like any other built-in toolbox inside of ArcMap. In order to be able to create one, you first need to create a new toolbox in the ArcCatalog window inside ArcMap by clicking the right mouse-button on selected “New -> Toolbox”. Then, select your new toolbox with the mouse cursor and right-click it, select “properties” and a wizard starts for creating your script tool that is stored in the toolbox you just created, specifying your input script file and specifying the input (as well as output) parameters and related data types a user can enter when he uses the script tool. You can also enhance the appearance of the tool by adding help messages. A script tool can be run by double-clicking the script icon stored in the toolbox, to be accessed from ArcCatalog.
Script tools and toolboxes go together: script tools must be created in a custom toolbox. In order to share script tools, you need to provide both toolbox and script(s).
What is a Python toolbox and how are they created?
A Python toolbox takes the concept of script tools and custom toolboxes one step further. Python toolboxes were introduced in ArcGIS 10.1, enabling easier sharing and programming of user script tools, plus adding extra capabilities not included with custom toolboxes – as well as some limitations. Here, all code is stored in a single file that combines Python code for the geoprocessing tools used as well as the interfaces of the final toolbox. The file extension used for Python toolboxes is .pyt, while a script tool uses .py for the separate Python script and .tbx for the custom toolbox. It is possible to configure an IDE so that it recognizes .pyt files and makes them editable as a regular script file that uses the .py extension. In the ArcCatalog window, both toolbox types are displayed with their file extension, so either .tbx or .pyt so they´re easily distinguishable, apart from having slightly different icons.
Creating and running a Python toolbox works the same way as with a custom toolbox. The toolbox requires the user to enter a name when you create one. By right-clicking the toolbox in the ArcCatalog window, and selecting “edit”, a Python IDE will open with a default template containing classes and modules needed for the tools. The user is required to configure this template without any wizard, so if you´re new to Python, you might want to start with creating script tools first (the ArcGIS Help section offers information on how to define the parameters of a Python toolbox). The template always ends with the user adding the source code from a Python script. After finishing the template, a refresh of the ArcCatalog page is required for an update of the code that is now ready to run.
Upcoming Programming ArcGIS with Python Classes
- Programming ArcGIS with Python Workshop – Introduction
- Programming ArcGIS with Python Workshop – Intermediate
- Advanced ArcGIS Programming with Python