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
- Close ArcMap
- Go to My addin folder and double click the 'makeaddin' python file
- Double click the 'Python Addin File
- 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