Add-ins provide an easy way to distribute user interface customizations to end users. No installation programs are necessary. A single compressed file with a file extension of .esriaddin is copied to a well-known folder and ArcGIS Desktop handles the rest. To simplify development even further an Add-In Wizard has been provided by ESRI. You can download the wizard from the ESRI website.
The Python Add-In wizard, which you can download at the link provided above, is a great resource for creating the necessary files for an add-in. It generates the required files for the add-ins from a visual interface. After downloading and unzipping the file from the ESRI website you’ll want to double click addin_assistant.exe in the addin_assistant/bin directory to run the wizard.
The add-in file structure is really quite simple. Two folders and a set of files comprise the add-in structure. The images folder contains any icons or other image files used by your add-in. The Install folder contains the Python script that handles the business logic of the add-in. This is the file you’ll work with extensively to code the add-in. It performs whatever business logic needs to be performed by the buttons, tools, menu items, etc. The config.xml file defines the user interface and any static properties such as the name, author, version, etc. The makeaddin.py file can be double clicked to create the .esriaddin file which wraps everything into a compressed file with an .esriaddin extension. This .esriaddin file is what will be distributed to end users.
There are a number of add-in types that can be created. The simplest type of add-ins are buttons and tools. Buttons simply execute business logic when clicked. Tools are similar to buttons but require interaction with the map before the business logic is executed. Combo boxes provide a list of choices for the user to select from. There are also a number of container objects including menus, toolbars, and tool palettes. Menus act as a container for buttons or other menus. Toolbars are a container for buttons, tools, combo boxes, tool palettes, and menus. They are the most versatile of the add-in container types. Finally, tool palettes act as a container for tools. Tool palettes need to be added to a toolbar before the tools will be exposed. Finally, application extensions are the most complex add-in type. This type of add in coordinates activities between other components and is responsible for listening for and responding to various events such as the addition or removal of a layer from a data frame.
Creating an add-in project is the first step in the creation of a new add-in. To create a project open the ArcGIS Python Add-In Wizard and select a working directory and then enter the various project settings. Finally, click the Save button, but don’t close the wizard. You still need to follow specific steps for creating the particular add-in you’d like to deploy.
The creation of an add-in follows a well defined process which is described on this slide. You must first create a container for the add-in and this will be either a toolbar or a menu. Next, create the button, tool, or other add-in you want to add to the container. In this case we’ll just assume it’s a button. Next, you need to edit the Python script associated with the button. You’ll also want to test the button to make sure it works as expected. Finally, you can share the add-in with others.
The first step is to create a container for your add-in. This is easily accomplished through the Python Add-In Wizard. Go to the Add-In Contents tab and right click the Toolbars Item. Select New Toolbar.
After the container Toolbar has been created you can then create the button or other type of add-in. In this case we’ll assume you’re creating a button. Right click the new Toolbar and select New Button. Then, fill in the button details which will be saved to the config.xml file. Click Save to save this information to config.xml.
Add-ins have a Python script that they are attached to. This file, by default, will be named AddIns_addin.py and can be found in the install directory of your working project folder. Inside the script you’ll want to locate the ‘onClick’ event. You’ll need to alter this function as needed to handle what happens when the button is clicked.
You’ll want to always test add-ins before distributing them to your end users. To test you first need to install the add-in. In the working folder for your add-in run the makeaddin.py script by double clicking it.
This copies all files and folders to a compressed add-in folder in a working directory with the file format: <working folder name>.esriaddin. Double click this .esriaddin file to launch the ESRI ArcGIS Add-In Installation Utility which will install your add-in. You can then go into ArcGIS Desktop and test your add in. The custom toolbar or menu may already be visible and ready to test. If it is not visible, go to the Customize menu and click Add-in Manager. The Add-In Manager dialog box lists the installed add-ins that are targeting the current application. Add-in information, such as name, description, and image, entered as project settings should be displayed.
If the add-in is listed in the manager, click the Customize button to open the Customize dialog box. To add a toolbar to the application, click the Toolbars tab and choose the toolbar you created. To add a menu to the application, click the Commands tab and scroll down the list of categories to [ MENUS ] and find your custom menu. Drag the menu onto an existing menu or toolbar. If the add-in is an extension, be sure it is enabled. Open the Extensions dialog box and check it to enable it.
Want to learn more about using Python with ArcGIS 10 and ArcGIS 10.1? We have a number of instructor led and self paced training opportunities.
Python ArcGIS Programming Bootcamp
Next Session: July 9th – August 10th