I created a python add-in using the python add-in assistant. The add-in included a class for triggering the openDocument (self) event. However, it never fires. I dumbed down the method to only include a pythonaddin.messagebox statement, with no luck at all.
If I use the same approach, but with the startup(self) event, it works great.
I've tried adding a delay using time.sleep without any success.
Using ArcGIS 10.2.2, windows 7.
Any help would be greatly appreciated.
Solved! Go to Solution.
Hmmm it seems to work for me.
1.) Created add-in using Python add-in assistent. One Extension with openDocument selected.
2.) Changed openDocument method to:
def openDocument(self): pythonaddins.MessageBox('This is a message box!', 'INFO', 0)
3.) Save add-in script and run makeaddin.py
4.) Run .esriaddin file to install
5.) Open ArcMap
6.) Enable new extension
7.) Open Python window
8.) Load a map document
9.) Message box appears
This only fires when a document is opened, not on ArcMap startup, unless you open an mxd at (approximately) the same time as startup (e.g. double-click an mxd outside ArcMap).
Hmmm it seems to work for me.
1.) Created add-in using Python add-in assistent. One Extension with openDocument selected.
2.) Changed openDocument method to:
def openDocument(self): pythonaddins.MessageBox('This is a message box!', 'INFO', 0)
3.) Save add-in script and run makeaddin.py
4.) Run .esriaddin file to install
5.) Open ArcMap
6.) Enable new extension
7.) Open Python window
8.) Load a map document
9.) Message box appears
This only fires when a document is opened, not on ArcMap startup, unless you open an mxd at (approximately) the same time as startup (e.g. double-click an mxd outside ArcMap).
Darren,
Appreciate the help. Missed step 6 which seems obvious in hindsight.
Thanks!
In step 6 what are you enabling? This is not an option in the Add In Manager, Customize - Extensions, etc. I have the same problem. I'm running a simple message box and it does nothing.
If you've successfully created the extension add-in, it should appear in the extension list. Step six enables the extension, similar to enabling Spatial Analyst, 3D Analyst, etc.
Thanks for the reply Darren.
I run the .esriaddin file to install this.
The Add in shows up in the Add Ins Manager but it does not exist in Extensions.
Here is the code. It works just fine in the ArcMap immediate window. Time delay is there as I have seen other postings where people mentioned things may not run on the startup method if ArcMap has not fully loaded. This has been pretty frustrating as testing has consisted of run it, nothing happens so start guessing. Any feedback is greatly appreciated.
import arcpy
import pythonaddins
import time
class messagebox(object):
"""Implementation for MsgBox_addin.messagebox (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
time.sleep(15)
return pythonaddins.MessageBox("fake fake fake", "TEST", 0)