How to enable sketch snap agents


This sample turns on the Edit Sketch snap agents and updates the snapping dialog window.

How to use

  1. Load one or more feature layers into an ArcMap session and Start Editing.
  2. Paste the code into VBA and run the subroutine.
[VBA]
Public Sub AddSketchSnapAgents()
    Dim pEditor As IEditor
    Dim pSnapPerpendicular As ISnapAgent
    Dim pSnapSketchEdge As ISnapAgent
    Dim pSnapSketchVertex As ISnapAgent
    Dim pSnapEnvironment As ISnapEnvironment
    Dim pID As New UID
    Dim pSnapWindow As ISnappingWindow
    
    pID = "esriEditor.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pID)
    Set pSnapEnvironment = pEditor
    
    'turn on each of the sketch snap agents
    Set pSnapPerpendicular = CreateObject("esriEditor.PerpendicularSnap")
    pSnapEnvironment.AddSnapAgent pSnapPerpendicular
    
    Set pSnapSketchEdge = CreateObject("esriEditor.SketchSnap")
    pSnapEnvironment.AddSnapAgent pSnapSketchEdge
    
    Set pSnapSketchVertex = CreateObject("esriEditor.AnchorSnap")
    pSnapEnvironment.AddSnapAgent pSnapSketchVertex
    
    'get the snapping window and refresh it
    pID = "esriEditor.SnappingWindow"
    Set pSnapWindow = pEditor.FindExtension(pID)
    
    If pSnapWindow Is Nothing Then Exit Sub
    
    pSnapWindow.RefreshContents
    
End Sub






Additional Requirements
  • An Edit Session.