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.
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
  Dim pSnapCommand As ICommand
  pID = "esricore.editor"
  Set pEditor = Application.FindExtensionByCLSID(pID)
  Set pSnapEnvironment = pEditor
  'turn on each of the sketch snap agents 
  Set pSnapPerpendicular = CreateObject("esricore.PerpendicularSnap")
  pSnapEnvironment.AddSnapAgent pSnapPerpendicular

  Set pSnapSketchEdge = CreateObject("esricore.SketchSnap")
  pSnapEnvironment.AddSnapAgent pSnapSketchEdge

  Set pSnapSketchVertex = CreateObject("esricore.AnchorSnap")
  pSnapEnvironment.AddSnapAgent pSnapSketchVertex
  'get the snapping window and refresh it 
  pID = "esriCore.SnappingCommand"
  Set pSnapCommand = Application.Document.CommandBars.Find(pID).Command
  If pSnapCommand Is Nothing Then Exit Sub
  Set pSnapWindow = pSnapCommand

End Sub