Getting results from your Python Add-in buttons

The new Python Add-ins for ArcGIS 10.1 bring a whole new opportunity for customizations.  The pythonaddins module provides additional functionality within add-ins that is not available in stand-alone scripts or geoprocessing script tools.  Three of these functions that allow user input or interaction are: OpenDialog, SaveDialog, and MessageBox.

Each of these functions allow information to be collected from the user.  It is up to the programmer to determine what to do with that information.

The OpenDialog and Save Dialog functions return two different values depending on how the user interacts with the dialog.  When the user selects a dataset and clicks either Open or Save, it returns the full path of the dataset chosen.  If the Cancel button is clicked it returns ‘None’.

Value being passed to a print statement when clicked.

The MessageBox function works in a similar way; however, it returns the string value representing the message button pressed.  For example, when the Ignore button is clicked it returns ‘Ignore’.

Below is a sample python add-in with comparison between the code and the dialogs:

A) The Open Dialog opens.
B) A file is chosen, and the Open button is clicked.  The file is added to the map.
C) The Cancel button is clicked which opens the Warning Message.
D) The Retry button is clicked which reopens the Open Dialog.
E) The Cancel button is clicked which opens a final Warning Message.

The above sample add-in is available on Dialog Windows and Messages

Timothy H. – Senior Support Analyst

About Timothy

Timothy Hales, GISP | Enterprise Community Manager| Esri Esri Certified ArcGIS Desktop Professional Esri Certified ArcGIS Desktop Developer Associate Twitter: @GISpathway
This entry was posted in ArcGIS Desktop, export and tagged , , , , . Bookmark the permalink.

Leave a Reply


  1. timmo1982 says:

    Great tips- Thanks very much for these as, at the time of writing, the knowledge base around AddinToolbars is still quite sparse.
    I have another question if you don’t mind- Is it possible to add some sort of ‘wait’ instruction when calling a tool within a toolbox? For example, I have a button on a addin toolbar which calls a GPS/GPX conversion tool. I’ve also added a message box after that to ask if the user would like to open the DNR GPS program as that is the logical next step for them- Ideally I would like to wait until the toolbox process is finished before I ask that question (currently it opens the message box as soon as the toolbox tool is opened)

  2. Timothy says:

    On first whim without doing any research I would use the ArcPy Exists function to see if the output of the tool has been created. You could create a loop that would check to see if it exists. If it does then launch the message, and if it does not then use time.sleep to wait before trying the exists function again.

    Exists (ArcPy)

    Time (Python)

  3. meier1ra says:

    Hi Timothy,

    I’m creating an interface using python and I want to prompt the user to add a shape file. I would like to use the python addin OpenDialog instead of the python tkinter OpenDialog, but I can’t figure out how to restrict it to just *.shp. When OpenDialog is run, it displays an option for “Show of type”, but I don’t know how to set it. It’s not listed as a parameter on the ArcGIS Resources page Is there a way to set it so the user can only choose *.shp files?