1

enter image description here

I can create multiple points using the add-in that I created. But the problem is, I don't know how to add edge and vertex identifiers to my tool (like in the picture).

Here is my code :

class ToolClass2(object):
"""Implementation for PPPpoint_addin.tool (Tool)"""
def __init__(self):
    self.enabled = True
    self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
def onMouseDownMap(self, x, y, button, shift):        
    fc = r"C:\Test\pourpoint.shp"

    pt = arcpy.Point()
    pt.X = float(x)
    pt.Y = float(y)

    ptGeoms = [arcpy.PointGeometry(pt)]
    cursor = arcpy.da.InsertCursor(fc, ['SHAPE@'])
    cursor.insertRow([pt])
    del cursor
4
  • 1
    Can you elaborate more on what the criteria is for adding edge and vertex points (when, where, why....)?
    – artwork21
    Aug 23, 2017 at 11:50
  • my point tool works like adding point tool of arcmap. But doesn't show edges and vertexes of other polygon and line type feature classes. I have to intersect my points with other polygons and lines. And i want to always use this identifiers while i create points. Because my all points have to intersect with other layers. Aug 23, 2017 at 11:58
  • I'm pretty sure this functionality isn't possible with pythonaddins. If you want to make the point you click align with edges or vertices, you will need to create the point after click, add the point to a feature class, and then use the snap tool on the feature class. Aug 23, 2017 at 15:53
  • Thank you Emil. You are my personal Jesus Christ. Snap method was what i was also thinking, if i fail finding a solution for edge identifiers. I guess i have to go with it. Aug 23, 2017 at 18:40

1 Answer 1

1

As mentioned in the comments, the functionality displaying "Edge" or "Vertex" is not possible with pythonaddins. The closest you can come is to create a point from the x and y coordinates and then making use of the Snap tool to achieve the same end result.

Here is a basic script:

sr = arcpy.SpatialReference (...spatial reference info...) #spatial reference object
moveLyr = "SnapToMeLayer" #layer to be snapped to edge or vertex

class AlignEdge (object):
    def onMouseUpMap(self, x, y, button, shift):
        point = arcpy.Point (x, y)
        clickGeom = arcpy.Geometry ("POINT", point, sr)
        arcpy.CreateFeatureclass_management ("in_memory", "pnt", "POINT",
                                             spatial_reference = sr)
        tempPntFc = r"in_memory\pnt"
        with arcpy.da.InsertCursor (tempPntFc, "SHAPE@") as curs:
            curs.insertRow ((clickGeom,))
        #snap 6 feet distance used to allow wiggle room with click
        arcpy.Snap_edit (tempPntFc, [[moveLyr, "EDGE", "6 FEET"]])
        #snapped x and y
        snapX, snapY = arcpy.da.SearchCursor (tempPntFc, "SHAPE@XY").next ()[0]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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