Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers

up vote 7 down vote accepted

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).

share|improve this answer
1  
Of course this would only be helpful during development; I believe the ArcGIS designers intend for you to test your script before building the addin (resources.arcgis.com/en/help/main/10.1/index.html#/…) –  cwa Feb 20 '13 at 23:47
    
This is what I do as well. I also use winpdb for embedded debugging. –  blah238 Feb 21 '13 at 0:42
    
Thanks for the suggestion. This is a little beyond my skill set. Is it difficult to implement? Is there any further information about this that I can use to learn? –  Mike Feb 21 '13 at 16:19
1  
I'm a python developer with limited ArcGIS experience, but I'm learning it. I'll update with more details after I figure them out. –  cwa Feb 21 '13 at 18:49
    
@blah238 how did you configure the embedded debugging? My addin will connect but drops the connection after it's loaded. –  ShaunLangley Nov 11 '13 at 23:00
show 1 more comment

Per @blah238's suggestion, the following script

  1. closes ArcMap (if open)
  2. creates Add-in
  3. installs Add-in silently
  4. re-opens ArcMap document

Save to directory containing makeaddin.py:

import os

#Location of ESRIRegAddIn.exe
esri = "C:/Program Files (x86)/Common Files/ArcGIS/bin/ESRIRegAddIn.exe"
cwd = os.getcwd()
mapdoc = <path to mxd>

#Close ArcMap if it is open
try:    os.system("TASKKILL /F /IM ArcMap.exe")
except:    pass

#Create ESRI Add-in file
os.system(os.path.join(cwd, "makeaddin.py"))

#Silently install Add-in file. The name of the file is based on folder it's located in.
os.system('"{0}" {1} /s'.format(esri, os.path.split(cwd)[-1] + ".esriaddin"))

#Open test map document.
os.system(mapdoc)
share|improve this answer
    
is this included in your PythonTool_addin.py file? –  ShaunLangley Sep 17 '13 at 1:45
    
@ShaunLangley, no this is a separate .py file residing in the directory of makeaddin.py –  Paul Sep 17 '13 at 3:22
add comment

I received an answer on the ArcGIS website. Apparently this is the only way to re-compile python addins. Someone has logged an idea on ArcGIS Ideas and I've voted up and commented as well.

ArcGIS Discussion Forum thread is located here.

share|improve this answer
1  
Could you add the relevant links to your answer? –  blah238 Feb 22 '13 at 20:15
    
I wanted to vote for but could not find the ArcGIS Idea that @Mike mentions. –  PolyGeo May 28 '13 at 22:22
    
Sorry, I didn't see this reply until now. Thanks @PolyGeo for updating the link to the ArcGIS website. –  Mike Jun 4 '13 at 16:27
add comment

I generally use two approaches: one is, for any tools you use that are really just geoprocessing, allow them to be imported, and then you can set up an interactive Python session, and do reload(mymodule) as mentioned to include the newest changes (or set up autoreload in IPython). If you are just making changes to a Python toolbox, you can reload the toolbox by right clicking on it in Catalog view and clicking 'Refresh'.

For code that does require user interaction in the GUI, I use the following batch script to speed up the process:

@echo off
echo building...
python makeaddin.py
echo installing...
start myaddin.esriaddin
echo load ArcMap...
start %HOMEDRIVE%%HOMEPATH%\Documents\ArcGIS\myaddin.mxd

Where myaddin.mxd has data layers and context that I use for the specific project. This will fire the addin install and ArcMap simultaneously, but I can usually click on the 'Install Add-in' button faster than ArcGIS starts. Alternatively, you could add pause before the last command to wait for input prior to starting ArcGIS.

share|improve this answer
    
You could use ESRIRegAddIn.exe with the /s switch to install the add-in silently. The path to ESRIRegAddIn on my machine is C:\Program Files (x86)\Common Files\ArcGIS\bin. –  blah238 Jun 5 '13 at 1:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.