Python Addin Tool Results in Crash

Discussion created by mahunter243 on Jun 23, 2012
Latest reply on Jan 9, 2013 by garridolecca.riveragmail-esridist
I think the Python addin idea is really good, but there is at least 1 show stopper right now.  I made a toolbar with a single tool to test.  Everything works fine until exactly 9 clicks with the tool, at which point arcmap crashes.  It's always 9 clicks and crash, very repeatable.  I'm running XP, SP3, and there's a single shapefile layer in the map, but I've tried it in several mxd's, and it's always the same result.  As you can see, the tool doesn't do anything except print the event args to the python window.  I'm almost certain the problem is in the onRectangle event, since the crash only occurs if self.shape is set to Rectangle.   I can set self.shape to None, and put "print self.down" in the onMouseDownMap def, and it will work all day long.  But I need rectangle for the tools I want to build. 

Below is the code. Jason or someone, if you can check this, I sure would appreciate it.  Python addins hold a lot of promise, and I'd sure like to be able to use them and get away from .NET.

import arcpy
import pythonaddins

class ToolClass2(object):
    """Implementation for ToolTest_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "Rectangle" # Can set to "Line", "Circle" or "Rectangle" 
        #for interactive shape drawing and to activate the 
        #onLine/Polygon/Circle event sinks.
        self.cursor = 3
        self.down = None
    def onMouseDownMap(self, x, y, button, shift):
        self.down = 'down', x, y, button, shift
    def onRectangle(self, rectangle_geometry):
        extent = rectangle_geometry
        s = ', '.join(('onrect', str(extent.XMin), str(extent.YMin), 
                        str(extent.XMax), str(extent.YMax)))
        print self.down
        print s
        self.down = None


PS:  Once this is fixed, we need more cursors, too.  In .NET we get unlimited cursors (make your own).