3
import arcpy
import pythonaddins
class point(object):
    """Implementation for point_addin.tool (Tool)"""
def __init__(self):
    self.enabled = True
    self.shape = "NONE"
def onMouseDownMap(self, x, y, button, shift):
    pt = arcpy.Point()
    pt.X = float(x)
    pt.Y = float(y)
    ptGeoms=[arcpy.PointGeometry(pt)]
    arcpy.CopyFeatures_management(ptGeoms, r"C:\test.shp")

There is a problem in my code. While i use this add-in in arcgis, it creates a new point on where i click, but the problem is, it deletes last point i created. I can not save my last point.

3

You're recreating the same feature class each time you use the Copy Features tool. As mentioned in the comments, you can use an insert cursor instead to add the feature to an existing feature class.

I'd do something like this:

import arcpy
import pythonaddins

mxd = arcpy.mapping.MapDocument ("CURRENT")
sr = mxd.activeDataFrame.spatialReference
pntFc = r"C:\test.shp"

class point(object):
    """Implementation for point_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
    def onMouseDownMap(self, x, y, button, shift):
        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 ()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.