Getting results from your Python Add-in buttons

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

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

OpenDialogScript5.jpg

The above sample add-in is available on ArcGIS.com: Dialog Windows and Messages

Timothy H. – Senior Support Analyst
About the Author
Timothy Hales is a Senior Education Specialist for Esri Training Services developing instructor-led and web courses. Before developing training content for Training Services, he was the Enterprise Community Manager for Esri Community (GeoNet).