There is a workaround for the crash. Create a tool for one of the geometry types - in there, in OnMouseDownMap create a point its x, y parameters. In OnMouseUpMap create another point. Essentially, you will click a point, hold down the mouse and release it at another location. Your rectangle will be created with these two points as opposite corner. In case of a circle, the first point will be the center and distance between two points will be the radius. Here is my code for rectangle class:class RectangleToolClass(object):
"""Implementation for AlternativeGeometries_addin.rect_tool (Tool)"""
def __init__(self):
self.enabled = True
self.shape = "NONE"
def onMouseDownMap(self, x, y, button, shift):
self.point1 = arcpy.Point(x, y)
def onMouseUpMap(self, x, y, button, shift):
self.point2 = arcpy.Point(x, y)
array = arcpy.Array()
array.add(self.point1)
array.add(arcpy.Point(self.point2.X, self.point1.Y))
array.add(self.point2)
array.add(arcpy.Point(self.point1.X, self.point2.Y))
array.add(self.point1)
g = arcpy.Polygon(array)
arcpy.CopyFeatures_management(g, r"in_memory\rectangle")
Your onMouseUp method for circle could be: def onMouseUpMap(self, x, y, button, shift):
self.point2 = arcpy.Point(x, y)
pt1 = arcpy.PointGeometry(self.point1)
pt2 = arcpy.PointGeometry(self.point2)
buff_dist = pt1.distanceTo(pt2)
arcpy.Buffer_analysis(pt1, r"in_memory\circle", buff_dist)
The line is simplest 🙂 def onMouseUpMap(self, x, y, button, shift):
self.point2 = arcpy.Point(x, y)
array = arcpy.Array()
array.add(self.point1)
array.add(self.point2)
g = arcpy.Polyline(array)
arcpy.CopyFeatures_management(g, r"in_memory\line")