Note: An example and additional explanation of this is available on ArcGIS.com.

ArcGIS for Desktop 10.1 introduces the capability to create custom Add-Ins using Python. Unfortunately this new functionality does not include the capability to create a custom dialog to enter parameters. Including a custom toolbox with the Add-In provides a solution. Here is how to do it.

ArcGIS for Python opens up a whole new realm of possibilities for GIS professionals who  have learned a little bit of Python to make life easier. I fall squarely into this category. the only difficulty is these Add-In's do not include the capability to create a dialog for collecting input parameters.

The ability to create a dialog for collecting input parameters is relatively straightforward when creating models and scripts in custom toolboxes. In fact, it is flat out easy. Already I have a number of models and tools contained in custom toolboxes I would like to include in a custom ArcGIS for Desktop Add-In.

It seems like there should be a way to combine these two functionalities. Although it took the better part of a day to sort out, it is possible to get the path where the currently executing script is located using a little functionality of the os.path module. If we place a custom toolbox in this same location as the script, we can use our Add-In button to call the tool from the toolbox.

To accomplish this, first create a Python Add-In with a button using the directions provided in the help documentation. The Python Add-In Assistant will create a number of files and directories in your Add-In directory. We are interested in is the Install directory.

Next, copy your custom toolbox into the Install directory you just created using the Python Add-In Assistant.

Now we need to edit the Python file inside the Install directory. The first file below (01-original.py) is what the file will look like when you first open it.

Modify this file to use the os module to import your toolbox and call your custom tool. Import the os.path module at the top. Get the directory path using the os functionality and finally use GPToolDialog to call the custom tool. The second file (02-modified.py) is what the file will look like once you have modified it to include this funcitonality.

In this way a custom toolbox can be used as part of an ArcGIS Desktop Add-In. This takes advantage of the ease of workflow automation offered through custom models and scripts inside of custom toolboxes. Integrating this into an Add-In makes it much easier to distribute desktop geoprocessing customization.