p.racz

Creating multiple points with mouse click

Discussion created by p.racz on Aug 23, 2017
Latest reply on Aug 24, 2017 by p.racz

Hi,

I am quite a beginner with Python, thus I will be grateful for your help .  I want to create multiple points on my map. I managed to do that but unfortunately my attribute table is not updating (it is always only one row even I added multiple points). Could you take a look at my code at tell me where is the problem? For any help thank you so much!

class Obstacle(object):
    """Implementation for new_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "circle" # 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):
        #workspace = r"\\\\abc\\home\\xxx\\Documents\\ArcGIS\\Default.gdb" 
        #adding points to the map
        mxd = arcpy.mapping.MapDocument ("CURRENT")
        sr = mxd.activeDataFrame.spatialReference
        pntFc = r"\\abc\home\xxx\Documents\ArcGIS\treepoints"
        pt = arcpy.Point()
        pt.X = float(x)
        pt.Y = float(y)
        ptGeoms = [arcpy.Geometry ("POINT", pt, sr)]
        if not arcpy.Exists (pntFc):
            arcpy.CopyFeatures_management(ptGeoms, pntFc)
        else:
            with arcpy.da.InsertCursor (pntFc, "SHAPE@") as iCurs:
                iCurs.insertRow (ptGeoms)
            arcpy.RefreshActiveView ()

 

Best,

Paulina

Outcomes