1

I'm trying to create snapping agent, I'm using the standard code from ESRI ArcObject Library, this code works perfectly on VB6/ArcGIS 9.3, but not on VB.net (3.5 SDK) and ArcGIS 10.

The property "SnapAgentCount" is empty :

pSnapEnv.SnapAgentCount = 0

=========================

Public Sub SetBufferSnapClass()
  On Error Resume Next
  Dim pApp As IApplication, pMap As IMap, pFeatLayer As IFeatureLayer
  Dim pEditor As IEditor
  Dim pSnapAgent As ISnapAgent
  Dim pSnapEnv As ISnapEnvironment
  Dim pEditLayers As IEditLayers
  Dim pMySnapAgent As BufferSnapPrj.BufferSnap 'use VB6 sample
  'Dim pMySnapAgent As BufferSnapVBNet.BufferSnap 'use VB.Net sample
  'Dim pMySnapAgent As BufferSnapCS.BufferSnap 'use C# sample
  Dim pUID As New UID
  Dim Count As Integer, Count2 As Integer

  pUID = "esriEditor.Editor"
  Set pApp = Application
  Set pEditor = pApp.FindExtensionByCLSID(pUID)
  Set pEditLayers = pEditor
  Set pSnapEnv = pEditor
  Set pMap = pEditor.Map
  'Find custom snap agent and set is featureclass property
  For Count2 = 0 To pMap.LayerCount - 1
    If UCase(pMap.Layer(Count2).Name) = "POLES" Then
      For Count = 0 To pSnapEnv.SnapAgentCount - 1
        Set pSnapAgent = pSnapEnv.SnapAgent(Count)
        If pSnapAgent.Name = "Buffer Snap" Then
          Set pMySnapAgent = pSnapAgent
          Set pFeatLayer = pMap.Layer(Count2)
          Set pMySnapAgent.FeatureClass = pFeatLayer.FeatureClass
        End If
      Next Count
      Exit For
    End If
  Next Count2
End Sub

If I activate "use classic snapping" under options on the Editor toolbar it works!

Is this the only way to do it because I don't want to use the standard Editor ToolBar?

1

Custom snap agents only apply to the classic snapping environment. You can choose the snapping environment through the editor options dialog or by setting the IEditProperties4.ClassicSnapping property.

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.