Creating Polygons with MouseDown

641
1
04-01-2013 03:54 PM
HoustonRudy
New Contributor
I would like to create an add-in using the "onMouseDown" and create polygon shape files.  I have done this with model builder, but I'm not sure how it works with Python.  I exported the Python code from the model, but it still didn't seem correct.  Has anyone had any experience creating custom polygons using mouse clicks?  Thanks.
Tags (2)
0 Kudos
1 Reply
HoustonRudy
New Contributor
I was able to get the first part to work (create polygon from mouse clicks).  However, now I am having issues with the "copy features" and "append" tools.  The end goal for the tool is for a user to be able to draw a polygon, save it, draw another polygon, and then append every polygon to that same file.  Below is the code I have so far: 

import arcpy
import pythonaddins
import os

class CreateNewPolygon(object):
    """Implementation for NewPolygon_addin.CPNtool (Tool)"""
   
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        self.shape = "Line"

    def onLine(self, line_geometry):
        array = arcpy.Array()
        part = line_geometry.getPart(0)
        for pt in part:
            print pt.X, pt.Y
            array.add(pt)
        array.add(line_geometry.firstPoint)
        polygon = arcpy.Polygon(array)
        
        # Local Variables
        Input = polygon
        NewPolygons = "C:\Arcfiles\test.gdb\NewPolygons"

        # Process: Append Polygon to existing file or Create new file if one is not created.  

        if arcpy.Exists("NewPolygons"):  
            arcpy.Append_management(Input, NewPolygons, "Test", "", "")

        else:
            arcpy.CopyFeatures_management(Input,NewPolygons, "", "0","0","0")
0 Kudos