Activate the Edit tool and Snap Operations Using Arcpy

150
0
07-10-2019 11:49 PM
gopi_chandangaluri
New Contributor
import arcpy
import pythonaddins
from arcpy import edit as EDIT
class Btn(object):
 """Implementation for Python_Snaptool_addin.button (Button)"""
 def __init__(self):
 self.enabled = True
 self.checked = False
 def onClick(self):
 pass
class Edit_Operations(object):
 """Implementation for Python_Snaptool_addin.extension20 (Extension)"""
 def __init__(self):
 # For performance considerations, please remove all unused methods in this class.
 self.enabled = True
 #edit = arcpy.da.Editor(r'D:\Sample.gdb')
 #self.onStartEditing()
 def startup(self):
 pass
 def onStartEditing(self):
 pythonaddins.MessageBox('Select a data frame', 'INFO', 0)
 pass
 def onStopEditing(self, save_changes):
 pass
 def onStartOperation(self):
 pass
 def beforeStopOperation(self):
 pass
 def onStopOperation(self):
 pass
 def onSaveEdits(self):
 pass
 def onCreateFeature(self):
 pass
class LineClass(object):
 """Implementation for Python_Snaptool_addin.tool (Tool)"""
 def __init__(self):
 self.enabled = True
 self.shape = "Line" # 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):
 global mid_point
 edit = arcpy.da.Editor(r'D:\Sample.gdb')
 array = arcpy.Array([arcpy.Point(line_geometry.firstPoint.X,line_geometry.firstPoint.Y),arcpy.Point(line_geometry.lastPoint.X,line_geometry.lastPoint.Y)]) 
 polyline = arcpy.Polyline(array)
 edit.startEditing()
 edit.startOperation() 
 cursor = arcpy.da.InsertCursor("CrossLine", ["SHAPE@"])
 cursor.insertRow([polyline])
 del cursor 
 mid_point = arcpy.Point() 
 mid_point.X= line_geometry.positionAlongLine(0.50,True).firstPoint.X
 mid_point.Y= line_geometry.positionAlongLine(0.50,True).firstPoint.Y
 edit.stopOperation()
 edit.stopEditing(True) ## Stop the edit session with True to save the changes
 arcpy.RefreshActiveView()
 obj = Edit_Operations()
 pass
 
 def onRectangle(self, rectangle_geometry):
 pass

Hi ,

could you help me

 

I need to snap the line feature after line drawn , also need to activate the Edit tool programmatically to select the annotation . 

requirement steps:

step 1  : create a line feature with snapping mode activation

step 2 : select the annotation

step 3 : snap the selected text to the mid point of the created line feature.

Intention of the code :

created  3 classes in addin 

one for line feature draw

two for select the annotation

three for button click if necessary

created a gdb (D:\Sample.gdb) 

created annotation and line feature classes for testing in arcmap using the addin tool.

 

Thanks

Gopi

0 Kudos
0 Replies