Python Add-In help please

1621
6
Jump to solution
04-05-2013 10:31 AM
JamesCrandall
MVP Frequent Contributor
I am struggling to get this working.  Attempting to follow along with Creating an addin tool

http://resources.arcgis.com/en/help/main/10.1/index.html#/tool/014p0000001q000000/

So, I have made it through Step 3 (and maybe my edits are not sticking or something, not sure).  Keeping things very simple, I just want to display a message box when the tool is clicked.

 def onRectangle(self, rectangle_geometry):     pythonaddins.MessageBox("Add-In executed!") 


However, moving on to "Testing an add-in" http://resources.arcgis.com/en/help/main/10.1/index.html#/Testing_an_add_in/014p00000026000000/

Step 2. does not work as epected.  I double-click the new .esriaddin file that was created and it asks me which program to use to open it.  Obviously, I don't know what to choose as it is just supposed to be some sort of ESRI dialog (per the Step 2. in the doc/link above).

So, ok -- I'll just run this in PythonWin.

It runs, but it does not create the expected GUID folder, nor does it copy the contents to the folder Documents\ArcGIS\AddIns\Desktop10.1.


Any help?
Thanks,
j
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisFox3
Occasional Contributor III
With regards to double-clicking the esriaddin file and it asking you which program to open with it sounds like there is a file association problem. Go ahead and right-click any esriaddin file and select Open With > Choose Default program and select ESRIRegAddIn.exe from C:\Program Files\Common Files\ArcGIS\bin.

With regards to the tool. It probably won't make a difference to the problem but go ahead and remove all the other functions in the tool you don't plan to implement, ie onMouseDown, onMouseUp, etc.

The behavior that controls whether you can click and drag and what shape is drawn is controlled by the shape property of the tool class. I see you have it set to Rectangle, so that seems correct. Try adding the same logic to onMouseDown and see if that even causes a messagebox to be shown.

Could you post the code with the intentional error you added?

View solution in original post

0 Kudos
6 Replies
JamesCrandall
MVP Frequent Contributor
If I just open ArcMap 10.1 and add the add-in via the Add-In Manager "Add From File", it does add the toolbar.  However, it does not operate as a tool (I am expecting to interact with the map, where once clicked it stays depressed and I can move the cursor over the map.  Similar to the Zoom tools). 

update: I can't even get an error to show (I have typed in an obviously incorrect line in the def_init below and have an open python window in ArcMap. You'd think it would throw an error when I run the tool, but nothing happens).

here's the .py source:


import arcpy
import pythonaddins

class GrabExtents2ToolClass(object):
    """Implementation for GrabExtents2_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        self.shape = 'Rectangle'
    
    def onMouseDown(self, x, y, button, shift):
        pass
    def onMouseDownMap(self, x, y, button, shift):
        pass
    def onMouseUp(self, x, y, button, shift):
        pass
    def onMouseUpMap(self, x, y, button, shift):
        pass
    def onMouseMove(self, x, y, button, shift):
        pass
    def onMouseMoveMap(self, x, y, button, shift):
        pass
    def onDblClick(self):
        pass
    def onKeyDown(self, keycode, shift):
        pass
    def onKeyUp(self, keycode, shift):
        pass
    def deactivate(self):
        pass
    def onCircle(self, circle_geometry):
        pass
    def onLine(self, line_geometry):
        pass
    def onRectangle(self, rectangle_geometry):
        pythonaddins.MessageBox("Add-In executed!")

0 Kudos
ChrisFox3
Occasional Contributor III
With regards to double-clicking the esriaddin file and it asking you which program to open with it sounds like there is a file association problem. Go ahead and right-click any esriaddin file and select Open With > Choose Default program and select ESRIRegAddIn.exe from C:\Program Files\Common Files\ArcGIS\bin.

With regards to the tool. It probably won't make a difference to the problem but go ahead and remove all the other functions in the tool you don't plan to implement, ie onMouseDown, onMouseUp, etc.

The behavior that controls whether you can click and drag and what shape is drawn is controlled by the shape property of the tool class. I see you have it set to Rectangle, so that seems correct. Try adding the same logic to onMouseDown and see if that even causes a messagebox to be shown.

Could you post the code with the intentional error you added?
0 Kudos
JamesCrandall
MVP Frequent Contributor
With regards to double-clicking the esriaddin file and it asking you which program to open with it sounds like there is a file association problem. Go ahead and right-click any esriaddin file and select Open With > Choose Default program and select ESRIRegAddIn.exe from C:\Program Files\Common Files\ArcGIS\bin.

With regards to the tool. It probably won't make a difference to the problem but go ahead and remove all the other functions in the tool you don't plan to implement, ie onMouseDown, onMouseUp, etc.

The behavior that controls whether you can click and drag and what shape is drawn is controlled by the shape property of the tool class. I see you have it set to Rectangle, so that seems correct. Try adding the same logic to onMouseDown and see if that even causes a messagebox to be shown.

Could you post the code with the intentional error you added?


Hi Chris -- thanks for the reply.

So, simply running the makeaddin.py from say PythonWin will not work?  It seems to create a new .esriaddin file each time!

1. I am unsure if your suggestion will work for me as we are in a Citrix environment.  There is no Program Files\Common Files\ArcGIS\bin\ESRIRegAddIn.exe available to us!  Can that ESRIRegAddIn.exe tool be copied and run from our Citrix environment?  I may have to use one of our server environments that has a full install of ArcGIS 10.1 on it in order to get this add-in built.

Unless you have a solution for us Citirx environment people?

2. Understood about removing all of the unnecessary functions.

3. I will try to move things to the onMouseDown.
0 Kudos
ChrisFox3
Occasional Contributor III
Hi Chris -- thanks for the reply.

So, simply running the makeaddin.py from say PythonWin will not work?  It seems to create a new .esriaddin file each time!

1. I am unsure if your suggestion will work for me as we are in a Citrix environment.  There is no Program Files\Common Files\ArcGIS\bin\ESRIRegAddIn.exe available to us!  Can that ESRIRegAddIn.exe tool be copied and run from our Citrix environment?  I may have to use one of our server environments that has a full install of ArcGIS 10.1 on it in order to get this add-in built.

Unless you have a solution for us Citirx environment people?


I am kind of confused, I understood that you had a problem when double-clicking the esriaddin file. The makeaddin.py is just a python script that will zip up all the contents of the addin into a single compressed file with a .esriaddin extension. So yes, it is intended behavior that a new .esriaddin file is created each time. As far as running the makeaddin.py file, you could run it from any Python IDE or if it is already associated with an install of python you should be able to just double-click it.

You don't need an install of ArcGIS 10.1 to build the python add-in, all you need is a version of python installed, i am not sure if there is a specific version, but 2.7 would be the best bet. This is because you only need to be able to run the makeaddin.py to build the add-in.

To install the add-in, ie double-click the .esriaddin file and pop up the installation utility, you do need ArcGIS 10.1 installed. This is because that utility is ESRIRegAddIn.exe which is installed with ArcGIS Desktop. In regards to a Citrix environment, if ArcGIS Desktop 10.1 was installed on the citrix machine the ESRIRegAddIn.exe should have already been associated with the .esriaddin file extension type for all users on the machine. This is really not specific to Citrix. If you are connecting to Citrix machine that has ArcGIS Desktop installed and attempting to double-click an .esriaddin file and no installation utility is launched it sounds like something broke the default file associations with these files. If that is the case you would want to work with the administrator of the machine to reestablish those file associations for all user.
0 Kudos
JamesCrandall
MVP Frequent Contributor
I am kind of confused, I understood that you had a problem when double-clicking the esriaddin file. The makeaddin.py is just a python script that will zip up all the contents of the addin into a single compressed file with a .esriaddin extension. So yes, it is intended behavior that a new .esriaddin file is created each time. As far as running the makeaddin.py file, you could run it from any Python IDE or if it is already associated with an install of python you should be able to just double-click it.


That's right.  If I double-click it as in the example, it wants me to specify the program to use to open it.  Also, I thought it  is supposed to create a new folder with a GUID -- that is following these steps:

http://resources.arcgis.com/en/help/main/10.1/index.html#/Testing_an_add_in/014p00000026000000/

Step 1. Fails.  I must right-click the makeaddin.py file and choose "Edit with PythonWin".  This creates the .esriaddin file.
Step 2. Fails.  Double-clicking the .esriaddin file wants me to specify a program to open it with.  With that, it does not create the folder with the GUID:

"The installation utility copies the add-in file to a generated subfolder under the default add-in folder; the subfolder is automatically generated using a globally unique identifier (GUID). This prevents file naming conflicts that might occur if several add-ins have the same file name."

Step 3. only works because I choose "Add From File" to add the Add-In to my ArcMap 10.1

Again, I am working in Citrix environment and there is no ESRIRegAddIn.exe file to be found anywhere. 

Thanks for your input!
James
0 Kudos
JamesCrandall
MVP Frequent Contributor
Resolved.

All of my issues/problems were related to Citrix environment and the setup of my specific user account.  With that said, my solution was to develop the Add-In on another box with all of the appropriate setup completed as outlined by Chris.  I simply access the box with Remote Access.

(I do have another question but will start a new thread)
0 Kudos