import arcpy
import pythonaddins
class ToolClassRandom(object):
"""Implementation for GenerateRandomPoints_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.cursor = 3
self.shape = 'Rectangle' # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
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):
extent = rectangle_geometry
arcpy.env.workspace = "c:\ArcpyBook\Ch11"
if arcpy.Exists("randompts.shp"):
arcpy.Delete_management("randompts.shp")
randompts = arcpy.CreateRandomPoints_management(arcpy.env.workspace,"randompts","randompts.shp","POINT",rectangle_geometry)
arcpy.RefreshActiveView()
return randompts
Been trying to run this code to create an addin for the Generate Random Points. It gave me the error that says:
Traceback (most recent call last):
File "C:\Users\Pollock\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{A6309427-3034-2E61-07C7-2A592C101F22}\GenerateRandomPoints_addin.py", line 41, in onRectangle
return randompts
UnboundLocalError: local variable 'randompts' referenced before assignment