Creating an Addin Extension that Responds to a Python Script

Discussion created by rfairhur24 Champion on Aug 23, 2012
Latest reply on Aug 27, 2012 by ldonahue
I want to know if it is possible to create an Add-in extension that listens for map refresh events to specifically respond to the actions of a python script?

I envision adding a hidden text object into a specific kind of map that will at first indicate to the Add-in Extension that nothing needs to be done.  When the Python script runs it will write to that text object to set a flag telling the Extension that it is processing a change to the map, so ignore any map refresh actions during the script processing.  Just prior to completion of the Python script, the Python script will update the Text Object to say that it just finished and needs the Extension to do its thing.  Then the Python script will refresh the map.  I assume the Add-in Extension can detect the map refresh event triggered by the Python script, read the text object to detect that python wants the extension to run and then the extension can fire its action on the map.  When the extension finishes it will reset the text object back to the state indicating that nothing needs to be done by the extension.

Does this sound like it will work?

I want the Add-in to detect when arcpy.mapping finishes updating everything that it can in the map, and then have the extension change the data frame clipping geometry to match a feature's shape according to the current definition query on a layer that the python script set.  I do not want the user to have to push another button after the Python script finishes to do things that Python seemingly cannot do, and I do not want the Add-in to do the Python script actions.  I do not see any other way to have Python trigger an ArcObjects action within the currently open map, since the ctypes functionality says it is limited to basic C++ types and I do not see a way to pass a hook for the current map to an ArcObjects DLL method from Python.

Please correct me if I am wrong about any of this or if there is a better approach to do what I want.