ESRI add-in
An add-in can be used to attach Python to standard controls like buttons or drop down selection lists. It can also be used from Data Driven Pages, so that some python runs each time a DDP page is selected.
It consists of a ZIP file with configuration and python code in it, with the extension changed from .zip to .esriaddin.
The easiest way to create one is to use the ESRI wizard to make a new project and then to modify the files to add your code.
Create an add-in
First create the template using the ESRI Python Add-In Wizard.
Add your code. (Just like that no additional help needed. :-)
This will give you a makeaddin.py script that you can run to build the .esriaddin file.
I use Visual Studio set to run makeaddin.py when I do an F5 to run the project.
I have ArcMap set to search my source directory on startup. (See Data Driven Pages for help.) Then I only need to reload ArcMap to test new versions.
What's in an esriaddin file?
I opened my DDP extension in emacs. It looks like this:
Filemode Length Date Time File ---------- -------- ----------- -------- ------------------------------- -rw-rw-rw- 1897 23-May-2018 15:22:30 config.xml -rw-rw-rw- 694 19-Apr-2018 12:18:14 README.txt -rw-rw-rw- 2834 30-Apr-2018 10:27:38 makeaddin.py -rw-rw-rw- 11951 20-Apr-2018 10:19:58 Images/cc_logo_64x64.png -rw-rw-rw- 27711 19-Apr-2018 10:12:54 Images/ormap.png -rw-rw-rw- 4543 23-May-2018 12:24:52 Install/ccmap.py -rw-rw-rw- 5859 23-May-2018 12:07:48 Install/arc_utilities.py -rw-rw-rw- 4293 18-May-2018 12:08:28 Install/cancellations.py -rw-rw-rw- 3182 28-Mar-2018 11:36:54 Install/mapnum.py -rw-rw-rw- 4592 11-May-2018 16:28:44 Install/MXDReport_tool.py -rw-rw-rw- 3932 29-Mar-2018 11:33:26 Install/mxd_report.py -rw-rw-rw- 10504 3-Apr-2018 16:52:26 Install/ormapnum.py -rw-rw-rw- 3400 3-Apr-2018 16:03:32 Install/printMaps.py -rw-rw-rw- 7128 21-May-2018 16:30:22 Install/PrintMaps_tool.py -rw-rw-rw- 13514 18-May-2018 12:37:22 Install/zoomToMapNumber.py -rw-rw-rw- 4336 21-May-2018 16:30:22 Install/ZoomToMapNumber_tool.py -rw-rw-rw- 186 12-Apr-2018 16:40:12 Install/__init__.py -rw-rw-rw- 2547 25-Apr-2018 16:49:52 Install/ORMAP_config.py ---------- -------- ----------- -------- ------------------------------- 113103 18 files
If you look in my source code you will see ONLY ccmap.py in the Install/ folder. I tweaked the makeaddin.py script to copy all the other files in there, so that I can share most of the code with other projects. There is probably a good way to do this directly in Visual Studio too.