Thursday 11 April 2019

arcpy - Re-compiling Python Addin after editing script?



I have been developing a few python addins and I'm just wondering what is the best way to re-compile the addin anytime I edit the script.


Currently, if I make an edit to the script, it seems like I have to



  1. Close ArcMap

  2. Go to My addin folder and double click the 'makeaddin' python file

  3. Double click the 'Python Addin File

  4. Restart ArcMap for the changes to come into effect


If I don't do these steps, then the edits aren't recognized. This gets pretty annoying and time consuming when I want to place maybe a simple print line somewhere or I do a small edit just to test a result.


Is there a better way of doing this?




Answer



You can use the builtin reload function in python to automatically reload your module. What you can do is something like this:


import mymodule

def hook():
reload(mymodule)
mymodule.myfunction()

where hook() is what's called by ArcMap and mymodule is the module you're editing between invocations. You may have to edit sys.path to include the path of the module you're editing so that import mymodule does not fail. Or include the directory in site-packages (maybe using python setup.py develop).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...