Creating ArcGIS Desktop Add-Ins Using Python and Related

Download Report

Transcript Creating ArcGIS Desktop Add-Ins Using Python and Related

CREATING ARCGIS DESKTOP ADD-INS
USING PYTHON AND RELATED
PACKAGES/MODULES
2016 AGIC Education and
Training Symposium
September 22, 2016
Erik Glenn
● Pima County ITD-GIS
Presentation Outline








Overview
20 minutes + 5 mins for questions
Types of add-ins
Creating add-ins
Testing, sharing, and extending add-ins
Simple example
Additional resources
Summary/Questions
What are Add-ins?

Desktop application customization




User interface
All Desktop products (ArcMap, ArcCatalog, ArcGlobe,
ArcScene)
Introduced at Desktop version 10.0
Very simple to distribute, install and use
When Should You Use Add-ins?


Limitations of toolboxes (custom & Python)
Increasing complexity:


Toolboxes => Desktop add-ins => Extending add-ins
What are you trying to accomplish?




Geoprocessing (ONLY FOR TRIGGERING…)
Rearranging existing tools or putting them in custom
toolbar (NO)
Interacting with user interface (YES!)
Running code based on response to a Desktop event
(YES!)
Benefits of Add-ins




Easy to build, install and share
Don’t need to build installation programs
Don’t require COM registration
Can build with three different development
environments:



.NET
Java
Python, too!
Python Add-ins vs. .NET/Java




Python Add-ins introduced at version 10.1
Even easier!
No DLLs
Can use ArcPy rather than ArcObjects


Fewer lines of code
Less development time
Limitations of Python Add-ins

Can’t use in ArcGIS Pro






Have to import a toolbox to Pro, or
use ArcGIS Pro SDK for .NET
Not backward-compatible
Can’t use full functionality of ArcObjects
No officially-supported module for custom user
interface components
Tool license level requirements still apply
Types of Python Add-ins



Toolbars are now
dockable!
Python and .NET
tools can reside
on the same
toolbar!
Buttons can also
be generated
through
Customize Mode
Add-in Manager, Extensions, and
Toolbars
Creating Python Add-ins

Python Add-in Wizard





Creates project folder with three main components:





Downloadable from Esri
Extract files
Use addin_assistant.exe located in bin folder
All related files needed to create add-ins are included
config.xml
Install folder (contains Python script with business logic)
Images folder
Next, use makeaddin.py to create archive
The resulting *.esriaddin file can be used to install the
add-in
Creating Python Add-ins (Cont’d)




Can add additional folders and files
Benefits of .esriaddin method
.esriaddin file is really just a compressed file
Well-known folders
Config.xml



Describes the add-in and its customizations
Created by Add-in Wizard
Shouldn’t need to be edited
Images Folder



Contains all graphics associated with the add-in
Images that show up for tools, Add-In Manager, etc.
Graphics copied into this folder automatically by
Add-In Wizard
Install Folder



Holds the Python script for the add-in
The script defines the behavior of the customizations
described in config.xml
Classes created by Add-In Wizard
All pertinent functions for each class also created
 Only need to keep those you will use


Additional folders and files can also be placed in this
folder
e.g. toolboxes, tools, data
 These will be compressed and included when the add-in is
created

Pythonaddins Module

Separate Python module
 Like
arcpy
 Includes functions for supporting Python add-ins
 Can only be used within a Python add-in, not in scripts
or script tools

Functions like OpenDialog(), MessageBox(),
GetSelectedTOCLayerorDataFrame(),
ProgressDialog()
Final Steps

Edit the Python script as needed



Don’t rename classes as class names are created by /
referenced in config.xml
Update functions
Delete all functions not implemented





For clarity
To ensure they’re never called by the application
Re-save the script
Create add-in by running makeaddin.py
Install the add-in by double-clicking the *.esriaddin file
Testing/Debugging/Editing



Take advantage of
your Python IDE
Use Print statements
and review Exception
Errors
Use Add-In Wizard to
made edits to existing
add-ins (can also edit
config.xml directly)
Sharing Add-ins




One small file makes it easy to share
Place in well-known location to install; remove to
uninstall
Add-in can be updated with new version by merely
overwriting the old file
Add-ins can be digitally signed for security



Linked to standard ITU X.509 digital certificate
Use ESRISignAddIn.exe utility that comes with Python Add-in
Wizard
Administrative setting in Desktop to control security for all
add-ins
Sharing Add-ins (Cont’d)



Email attachment
Placing in shared directory that’s added to list of
well-known folder locations
ArcGIS Online
Extending Python Add-ins




Additional functionality, graphics, interfaces
Thousands of 3rd-party libraries =>
Python Package Index
Is a GIS category (browse under
“Scientific/Engineering”)
Examples:




wxPython
Plotly
ReportLab
R, Pandas, SciPy, GDAL, Numpy, Shapely, Pysal…
wxPython




A GUI toolkit for Python
Is Python extension module that wraps around
wxWidgets library (C++)
Can use wxGlade, a GUI designer that creates
wxPython code
Eric Pimpler (GeoSpatial Training Services) has
created a great Add-in using wxPython
ReportLab



A PDF toolkit for Python
Can be used to create data-driven PDF documents
and custom vector graphics
Three layers:
A
graphics canvas API that renders PDF pages
 A charts and widgets library for creating data
graphics
 A page layout engine that builds documents from
elements
Simple Example:
StreetView Add-In
Acknowledgements /
Additional Resources


Ian Broad, Thinking Spatially (blog @ ianbroad.com)
GeoSpatial Training Services


Several Python training courses
Eric Pimpler’s books:




Programming ArcGIS with Python Cookbook
ArcGIS Blueprints
ArcGIS Desktop help docs
Downloadable ArcGIS Desktop Python Add-ins on
ArcGIS Online (search for tools and ArcGIS Desktop
Content)
Acknowledgements /
Additional Resources

Python add-in class properties and functions:
desktop.arcgis.com/en/arcmap/latest/analyze/pythonaddins/button-class.htm , …/combobox-class.htm ,
…/tool-class.htm , …/extension.class.htm






wxpython.org
blog.pythonlibrary.org/category/wxpython
reportlab.com/opensource
plot.ly
pypi.python.org
packaging.python.org
Summary




Python add-ins are a great way to customize the user
interface for any of the ArcGIS Desktop products
Yes, there are limitations…
Regardless, they’re fairly easy to create, edit,
distribute and use
Until Desktop is deprecated (?) and Pro takes over,
they will continue to be forward-compatible with
future versions
Questions?
Erik Glenn
Senior GIS Analyst
Pima County ITD-GIS
33 N Stone Ave, 15th Floor
Tucson, AZ 85701-1439
[email protected]
(520) 724-6604