The Power of Python Toolboxes

A lot of manual work can be avoided by using scripts to automate the processes. However, you inevitably end up with a lot of scripts to automate different pieces of a process.

Python toolboxes provide a nice way to bundle these scripts for a complete solution to a process. It contains the whole process in one, admittedly large, script, with a template that includes error checking.

The complete documentation is here.

Create a file with a .pyt instead of .py

By re-labelling a python file to have the .pyt extension, rather than .py, ArcMap and ArcPro natively pick the python file up as a toolbox. There is a framework involving a few classes which you can copy and paste into your file. Then once your script is configured as a toolbox should be, you can then add it to your project and have others on the team follow a process.

One of the features of the .pyt I love is the ability to categorize, as I have above. Keeping a sub directory for ‘setup’ and ‘specialized tools’.

Above I’m treating the toolbox similarly to Tasks in ArcPro, whereby you can predefine a workflow. The exception being that you can leverage the power of custom code.

Saving Values using python

Using the toolbox above, if I click on the ‘Setup Project INI’ function, I get given a nice clean data entry form:

These are global variables which I need to systematically add to all of the assets that are being updated. By using a script I can take all of the values entered here, save them to an .ini file (basically just a .txt file) and then refer to the appropriate values whenever an asset needs an update.

Data Types

Another cool feature of the toolbox is it provides a nice platform or framework for doing data entry, which an extensive list of datatypes that can be referred to. Here is a complete list of data types. In the example below I am specifying a string type using the “GPString” which arcPro then uses to configure the data entry box.

My apologies for the brevity of this post, I just wanted to share how useful I find python toolboxes.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: