Getting results from your Python Add-in buttons

12-11-2012 02:30 AM
Labels (1)
Esri Notable Contributor
0 0 723
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.OpenDialogWindows.jpg


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

Timothy H. – Senior Support Analyst
About the Author
Education Specialist for Esri Training. Former Enterprise Community Manager for GeoNet and Senior Support Analyst for Esri Technical Support. Passion for technology, social media, and debt free living. Enjoy spending time with my family and running obstacle course races (completed my first Spartan Trifecta in 2015).