ArcGIS SDK  

Extending ArcObjects

Subtypes Snap Agent Example

In this section:

  1. The case for a subtypes snap agent
  2. Creating a snap agent
  3. Creating the SubtypesSnap agent
  4. Plugging the SubtypesSnap agent into ArcMap
  5. Creating an editor extension
  6. Creating the SnapExtension
  7. Creating the SnapDockableWindow
  8. Creating the ShowSnapWindow command

Subtypes Snap Agent Example

Object Model Diagram Click here.

Example Code Click here.

Description This project provides a custom snap agent that can be used to snap to particular subtypes of features while editing. A dockable window helps to manage the snap agent, and a command allows you to show and hide this dockable window. An editor extension ties all the custom classes together.

License required ArcEditor or above

Libraries ArcMapUI, Carto, Display, Editor, Framework, Geodatabase, Geometry, System, and SystemUI

Languages Visual Basic

Categories ESRI Snap Agents, ESRI Editor Extensions, ESRI Dockable Windows, and ESRI Mx Commands

Interfaces ISnapAgent, ISnapAgentFeedback, IPersistVariant, IExtension, IDockableWindowDef, and ICommand

How to use

    1. Register the SnapAgentVB.dll and double-click the SnapAgentVB.reg file to register to component categories.
    2. Open ArcMap, click Tools, then click Customize.
    3. In the Customize dialog box, click the Commands tab, then click on 'Extending ArcObjects' in the left-hand Categories list.
    4. In the Commands list, choose the SubTypesSnap Dockable Window command, and drag this onto the Editor toolbar below the Snapping command. Click Close to dismiss the Customize dialog box.
    5. Add data from a geodatabase to ArcMap—at least one of your data layers should contain a number of subtypes.
    6. Click Editor and click Start Editing.
    7. Click Editor again, and click Snapping to display the Snapping Environment Dockable Window. You should see the Sub Types snap agent listed under Miscellaneous in the lower half of the window.
    8. Click Editor once again, and click the custom SupTypesSnap Dockable Window command to show the Extended Snap Agents dockable window.
    9. You can now perform edits using the custom snap agent, and snap only to those subtypes selected in the Extended Snap Agents window.

The case for a subtypes snap agent

By using the standard editing functionality in ArcMap, you can create new features by snapping to the vertices, edges, or ends of the existing features.

However, if your data has subtypes and you would like to snap to only certain of the subtypes, you cannot do this using the existing functionality.

A custom snap agent mimics the standard feature snap agents except that it additionally checks for subtypes. The snap agents will have properties controlling which feature class and which subtype it targets.

This example demonstrates how to create a custom snap agent that can snap the edit sketch to specific subtypes of features in the existing feature classes.


Creating a Snap Agent

By reviewing the Editor object model diagram, you will see the SnapAgent abstract class, which implements ISnapAgent and also, optionally, ISnapAgentCategory and ISnapAgentFeedback. You can also see the FeatureSnap coclass, which implements its own IFeatureSnapAgent interface.

ISnapAgentFeedback allows snap agents to report back to the user what was snapped to. For example, feature snap agents report back the feature class and geometry part (vertex, edge, end) they successfully snapped to. ISnapAgentCategory helps organize regular snap agents by grouping them in categories in the bottom half of the snap environment dialog box as illustrated below. (This has nothing to do with component categories.) For example, all snap agents that work with the edit sketch are classified under Edit Sketch. Using ISnapAgentCategory, you can group your custom snap agents in an existing category or create your own.


Creating the SubtypesSnap Agent

To meet the requirements described above, you will create a subtype of the SnapAgent abstract class by implementing ISnapAgent and ISnapAgentFeedback. You will not implement IExtension, as you will create a separate extension class (see the section later in this topic for more information). You will make the snap agent persistable by implementing IPersistVariant (as the example code is in VB6). You will also create a custom interface, ISubtypesSnap, to allow access to the custom functionality of your class.


The design of the snap agent will be such that a new agent will be created for each subtype of each feature class in the current map.

As you saw in About Snap Agents, each agent is part of a larger Snapping Environment framework. The snapping environment sets up snap agents and allows a user to control their properties and state. The SubtypesSnap cannot be used in isolation—an essential part of this customization is the accompanying editor extension and dockable window, which are discussed later in this example.

Creating and Implementing ISubtypesSnapAgent

Your SubtypesSnap needs to be able to identify which Subtype of which FeatureClass it needs to snap to. You also need to be able to turn the snap agent on and off, as you can for other snap agents by selecting and deselecting the agent in the Snapping Environment dockable window. As there may be many snap agents, one for each subtype in each feature class, you should be able to name the snap agent.

To achieve these goals, create an interface called ISubtypesSnapAgent. Add five read-write properties to the interface to allow another class to set a FeatureClass, a SubtypeName and SubtypeCode, and a boolean to indicate if the agent is switched on.


The custom ISubtypesSnapAgent interface will allow clients to specify which FeatureClass and subtype the agent snaps to and also to identify each snap agent individually.

Now implement ISubtypesSnapAgent in your SubtypesSnap class. Create member variables to store the values of its properties. Implement each property to store or return the appropriate variable, as shown in the FeatureClass property below.

[Visual Basic 6]
Private m_pFeatureClass As esriGeoDatabase.IFeatureClass ' The snap FeatureClass
Private m_lCode As Long      ' The snap Subtype code
Private m_sName As String    ' The snap agent name
Private m_bIsOn As Boolean   ' Is the agent active?
  
Private Property Get ISubtypesSnapAgent_FeatureClass() As esriGeoDatabase.IFeatureClass
  Set ISubtypesSnapAgent_FeatureClass = m_pFeatureClass
End Property
  
Private Property Set ISubtypesSnapAgent_FeatureClass(RHS As esriGeoDatabase.IFeatureClass)
  Set m_pFeatureClass = RHS
End Propert

Implementing ISnapAgent

The Name property should return the string you want to be displayed in the Snapping Environment dockable window.

[Visual Basic 6]
Private Property Get ISnapAgent_Name() As String
  ISnapAgent_Name = "Sub Types"
End Propert

Performing the Snap with a FeatureCache

To activate a snap agent, a user starts an edit session and checks the snap agent required in the Snapping Environment dockable window. When an agent is activated and the current tool is one of the sketch tools, the ISnapAgent::Snap method will be called every time the mouse moves. This results in many calls, so to increase performance, the snap agent will use a feature cache.

A feature cache improves snapping performance because it holds onto a small subset (cache) of features from the area immediately surrounding the current tool location; when testing for hits, the snap agent only has to cycle through this subset of features rather than all the features in the database. Note, when the mouse next moves and the whole process begins all over again, the current cache of features is usually still relevant and does not need remaking. Only after the mouse has moved beyond the extent of the cache does it need to be refilled, and this is usually after many mouse moves.


Add a member variable to store your FeatureCache, and add a function to fill the cache. You will fill and use this cache in the Snap member below.

[Visual Basic 6]
Private m_FeatureCache As esriCarto.IFeatureCache
...
Private Sub FillCache(FClass As IFeatureClass, pPoint As IPoint, Distance As Double)
  m_FeatureCache.Initialize pPoint, Distance
  m_FeatureCache.AddFeatures FClass
End Sub

As you can see above, a FeatureCache can be automatically filled with features from a specified FeatureClass, based on a central point and a maximum distance. For more information about working with feature caches, see the Carto Library Reference.

The actual snapping behavior of the snap agent occurs in the Snap method. The Editor passes a point to this routine, which typically represents the current mouse location. You need to use this point to perform the snap.

  1. First, check that the snap agent is turned on, and a feature class has been set. If you exit the function without having performed a snap, return False.
    [Visual Basic 6]
    If Not m_bIsOn Then
      ISnapAgent_Snap = False
      Exit Function
    End If
    If m_pFeatureClass Is Nothing Then
      ISnapAgent_Snap = False
      Exit Function
    End If
  2. Check that the feature cache is full, and if the feature falls outside the extent of the feature cache, refill the cache centered on the new Point. The example code uses a distance of ten times the tolerance distance, Tolerance, which is passed in as a parameter to the Snap member.
    [Visual Basic 6]
    Dim dMinDist As Double
      dMinDist = Tolerance * 10
      
      If m_FeatureCache Is Nothing Then
        Set m_FeatureCache = New FeatureCache
      End If
      If Not m_FeatureCache.Contains(Point) Then
        FillCache m_pFeatureClass, Point, dMinDist
      End If
  3. Now you can perform the main test of the Snap method, which is to work out which is the closest vertex on the cached features to the Point variable (which is passed in as a parameter to the Snap member). The important elements of the code below are:
    • Loop through all of the features in the cache.
    • Ignore features with the wrong Subtype code.
    • Use the HitTest method to work out which is the closed point on the feature to the input Point.
    • If the HitPoint is closer than the current minimum distance, save the HitPoint, set the new minimum distance value, and set bHasSnapped to indicate that a snap has taken place.
    • The hit test is performed using the esriGeometryPartBoundary esriGeometryHitPartType constant, indicating that the sketch will snap to the closest point on anywhere on the boundary of a polygon feature or anywhere along a polyline feature, not necessarily to a vertex of the feature.
    [Visual Basic 6]
    ' pHitPoint will be used in the For loop below.
    Dim pHitPoint As IPoint
    Set pHitPoint = New Point
      
    ' Loop thru all of the features
    Dim pFeature As IFeature
    Dim pRowSubtypes As IRowSubtypes
    Dim pHitTest As IHitTest
    Dim bHasSnapped As Boolean
    Dim lPartIndex As Long, lSegmentIndex As Long, bRightSide As Boolean
    Dim dDist As Double, dX As Double, dY As Double
    Dim count As Integer
    For count = 0 To m_FeatureCache.count - 1
      Set pFeature = m_FeatureCache.Feature(count)
      Set pRowSubtypes = pFeature 'QI
      
      ' Only interrogate features that match subtype code
      If pRowSubtypes.SubtypeCode = m_lCode Then
        Set pHitTest = pFeature.Shape
        If (pHitTest.HitTest(Point, Tolerance, esriGeometryPartBoundary, pHitPoint, dDist, lPartIndex, lSegmentIndex, bRightSide)) Then
          If dDist < dMinDist Then
            pHitPoint.QueryCoords dX, dY
            dMinDist = dDist
            bHasSnapped = True
          End If
        End If
      End If
    Next count
  4. Perform a last check to make sure the hit distance, minDist, is within the search tolerance.
    [Visual Basic 6]
    If dMinDist >= Tolerance Then
      ISnapAgent_Snap = False
      Exit Function
    End If
  5. If the bHasSnapped variable indicates that the code found a snap point, modify the coordinates of the Point parameter, which was passed in to the Snap function to reflect those of the snap point you found in the loop, and return true.
    [Visual Basic 6]
    If bHasSnapped Then
      Point.PutCoords dX, dY
      ISnapAgent_Snap = True
    End If

Implementing ISnapAgentFeedback

The SnapText property should return a string indicating what was snapped to. You can return a string indicating the Object ID, Part, and Segment that was snapped to by writing a string with this information in the Snap member. Add a member variable to store the latest SnapText value, m_sSnapText, and edit Snap as shown.

[Visual Basic 6]
If dDist < dMinDist Then
  pHitPoint.QueryCoords dX, dY
  dMinDist = dDist
  bHasSnapped = True
  m_sSnapText = "OID:" & pFeature.OID & "; Part:" & lPartIndex & "; Segment:" & lSegmentIndex
End If
  
...
  
Private Property Get ISnapAgentFeedback_SnapText() As String
  ISnapAgentFeedback_SnapText = m_sSnapText
End Property

Implementing IPersistStream/IPersistVariant

Persistence functionality is essential for a snap agent. (If you are working in VC++ you should implement IPersist and IPersistStream; if working in VB, implement IPersistVariant.)

Snap agents must be persistable. See Chapter 2, 'Developing Objects', for general information on coding persistence methods.

Add a standard implementation of persistence to the SubtypesSnap agent. You may want to account for having an instantiated SnapAgent where its FeatureClass (and indeed other properties) has not been set yet, as shown below.

[Visual Basic 6]
Private Sub IPersistVariant_Save(ByVal Stream As esriSystem.IVariantStream)
  Stream.Write c_PersistVersion
  Stream.Write m_bIsOn
  
  If m_pFeatureClass Is Nothing Then
    Stream.Write False
  Else
    Stream.Write True
  
    Dim pDataset As esriGeoDatabase.IDataset
    Set pDataset = m_pFeatureClass
    Stream.Write pDataset.FullName
    Stream.Write m_sName
    Stream.Write m_lCode
  End If
End Sub

In the Load method, read the boolean value to determine if there are a FeatureClass, Name, and Code to read or not.

[Visual Basic 6]
Private Sub IPersistVariant_Load(ByVal Stream As esriSystem.IVariantStream)
  ...
  Dim hasFeatClass As Boolean
  hasFeatClass = Stream.Read
  If hasFeatClass Then
    Dim pName As esriSystem.IName
    Set pName = Stream.Read
    m_sName = Stream.Read
    m_lCode = Stream.Read
    Set m_pFeatureClass = pName.Open
  End If
End Sub

The SubtypesSnap agent should be registered to the ESRI Snap Agents component category.


Plugging the SubtypesSnap agent into ArcMap

At this point, you have a working Snap Agent. However, writing a custom snap agent solves only half of the requirements outlined in the scenario. The problem also requires a mechanism for automatically creating and adding the snap agents to the editor's snap environment. Similarly, the custom snap agents have properties that must be set and a means for turning them on and off.

You can solve this problem with a custom editor extension that automatically creates a subtype snap agent for each subtype it finds in the edit session. The extension should additionally expose a custom dockable window to enable users to turn the snap agents on or off. To complete the customization, create a custom command to open and close the dockable window.


Creating an Editor Extension

All editor extensions must implement the IExtension interface and be persistable. You can see a number of editor extension classes on the Editor Extension object model diagram.

Editor extensions do not implement IExtensionConfig (and, therefore, they do not show up in the Extensions dialog box), as the user is not expected to switch the extension on and off. Instead, each editor extension should be activated when an edit session begins and deactivated when the session ends.



Creating the SnapExtension

You need to provide a mechanism for automatically creating and adding the subtype snap agents discussed above into the editor's snap environment and to set the feature class and subtype properties of each SubtypeSnap. The keyword in this scenario is "automatic". Commands need pressing; tools require interactivity; the only option for this case is a custom editor extension.

You will create an editor extension class called SnapExtension. In this case, the extension will be a client to the editor events OnStartEditing. Whenever an edit session is started, the extension will automatically create a new subtype snap agent for each subtype it finds in the edit session.


You will also create a dockable window, following a similar design to the Snapping Environment dockable window, to enable users to turn the individual SubtypeSnap agents on and off. To complete the customization, you will need to add a custom command to open and close the dockable window. You can find a discussion of how to implement these classes following this SnapExtension section.

The Snap Form

Add to the project a form containing a Frame, which contains a ListBox. No code is required in the form class. This form will be used by the SnapExtension.

Implementing IExtension

As mentioned earlier, when an editor extension is loaded, its IExtension::Startup routine is called and a reference to the Editor object is passed in via the initializationData parameter. In this method you will need to store a reference to the Editor object and also sink the IEditorEvents interface.

[Visual Basic 6]
Private Sub IExtension_Startup(initializationData As Variant)
  If initializationData Is Nothing Then Exit Sub
  If Not TypeOf initializationData Is IEditor Then Exit Sub
  Set m_pEditor = initializationData
  Set m_pSnapEnv = m_pEditor
  Set EditorEvents = m_pEditor

At this point, you need to instantiate the Snap Form used by the SnapDockableWindow to display the SubtypeSnap agents to the user. You can then find the SnapDockableWindow. The actions are performed in this order because the SnapDockableWindow will ask the SnapExtension for the window handle to the form, and therefore, the form needs to be instantiated before you find the dockable window. (See below for a discussion of the dockable window class.)

[Visual Basic 6]
Set m_snapForm = New SnapAgentVB.SnapForm
Load m_snapForm
Set ListBoxEvents = m_snapForm.List1
  
Dim pUID As New esriSystem.UID
pUID.Value = "SnapAgentVB.SnapDockableWindow"
  
Dim pDockWinMgr As esriFramework.IDockableWindowManager
Set pDockWinMgr = m_pEditor.Parent
Set m_pDockWin = pDockWinMgr.GetDockableWindow(pUID)

The code above also shows that you will listen to events from the ListBox on the Snap Form so that the Extension itself can respond when a user makes changes in the selection of SubtypeSnap agents.

Implementing IEditEvents

The IExtensionStartup method above begins listening to the IEditEvents interface. To activate your extension when the user starts editing, sink the OnStartEditing event. In this method, you need to set up the SubtypesSnap agents.

[Visual Basic 6]
Private Sub EditorEvents_OnStartEditing()
  ' Don't bother looking for subtypes if the workspace is file based
  If Not m_pEditor.EditWorkspace.Type = esriFileSystemWorkspace Then
    ' Create an Array object that will locally manage the snap agents
    Set m_pSnapAgentArray = New esriSystem.Array
    SetUp
  End If
End Sub

The internal method SetUp should set up a new SubtypeSnap agent for each subtype of each feature class in the map. Full details of the process which is used to create the snap agents can be found in the sample project code; however, the main points of this function are as follows:

    1. Determine which feature classes in the edit session workspace are actually in the edit session.
    2. Find all the feature classes in the Map that have subtypes.
      [Visual Basic 6]
      If TypeOf pFeatureClass Is esriGeoDatabase.ISubtypes Then
        Set pSubtypes = pFeatureClass
        If pSubtypes.HasSubtype Then
          pMySet.Add pFeatureClass
        End If
      End If
    3. For each feature class, enumerate the subtypes.
      [Visual Basic 6]
      Set pEnumSubtypes = pSubtypes.Subtypes
      pEnumSubtypes.Reset
      newSubtypeName = pEnumSubtypes.Next(newSubtypeCode
    4. For each subtype found, check that a snap agent does not already exist for that subtype—a snap agent may have been saved in the document or an edit session which was started, stopped, and restarted. Do this by iterating all the snap agents in the snapping environment, m_pSnapEnv, looking for snap agents that implement ISubtypesSnapAgent and have a matching SubtypeName.
    5. Create a new SubtypesSnap agent for each subtype found, and set its FeatureClass, SubtypeCode, and SubtypeName.
      [Visual Basic 6]
      Set newSnapAgent = New SnapAgentVB.SubtypesSnap
      Set newSnapAgent.FeatureClass = pSubtypes
      newSnapAgent.SubtypeCode = newSubtypeCode
      newSnapAgent.SubtypeName = newSubtypeNam
    6. Add each agent to the Editor's snapping environment.
      [Visual Basic 6]
      m_pSnapEnv.AddSnapAgent newSnapAgen
    7. For each agent, add an item to the list box on the Snap Form, indicating if the snapAgent is selected or not.
      [Visual Basic 6]
      m_snapForm.List1.AddItem newSnapAgent.FeatureClass.AliasName + vbTab + newSnapAgent.SubtypeName
      If newSnapAgent.IsOn Then
        m_snapForm.List1.Selected(m_snapForm.List1.ListCount - 1) = True
      End If
    8. Add a reference to each new SubtypesSnap agent to an array stored as a member variable of the extension. You will use this in the following section.
      [Visual Basic 6]
      Private m_pSnapAgentArray As esriSystem.IArray
        
      ...
        
      m_pSnapAgentArray.Add newSnapAgen

In the OnStopEditing method, clear the Snap Form of items. In the next edit session, there may be entirely different feature classes and subtypes. Also, hide the SnapDockableWindow (other editor windows, such as Snapping Environment and Attributes, are automatically hidden when the user stops the edit session.

[Visual Basic 6]
Private Sub EditorEvents_OnStopEditing(ByVal Save As Boolean)
  If Not Save Then
    If Not m_snapForm Is Nothing Then
      m_snapForm.List1.Clear
    End If
    
    If m_pDockWin.IsVisible Then
      m_pDockWin.Show False
    End If
  End If
End Sub

Listening to ListBoxEvents

To respond to a user selecting and deselecting the snap agents in the dockable window, sink the ListboxEvents interface.

In the ItemChecked event, synchronize the listed snap agents' state with the state of the actual SubtypeSnap agent objects. If the listed agent is checked, make sure the corresponding SubtypeSnap agent is turned on.

[Visual Basic 6]
Private Sub ListBoxEvents_ItemCheck(Item As Integer)
  Dim pSubtypesSnapAgent As SnapAgentVB.ISubtypesSnapAgent
  Set pSubtypesSnapAgent = m_pSnapAgentArray.Element(Item)
  
  If pSubtypesSnapAgent Is Nothing Then Exit Sub
  If m_snapForm.List1.Selected(Item) = True Then
    pSubtypesSnapAgent.IsOn = True
  Else
    pSubtypesSnapAgent.IsOn = False
  End If
End Sub

Creating and Implementing ISubtypesSnapExtension

As discussed above under 'Implementing IExtension', the SnapDockableWindow needs to be able to get the window handle of the Snap Form m_snapForm from the SnapExtension. Also, the SnapDockableWindow will be made visible and invisible by the ShowSnapWindow command.

Create an interface called ISubtypesSnapExtension. Add a read-only property to identify whether the window SnapDockableWindow is visible and a method to toggle the visibility. Add another read-only property to return the window handle of the Snap Form.


The custom ISubtypesSnapExtension interface will allow the other classes in the component to show and hide the SnapDockableWindow.

Now implement ISubtypesSnapExtension in your SubtypesSnap class.

[Visual Basic 6]
Private Property Get ISubtypesSnapExtension_IsDialogVisible() As Boolean
  If m_pDockWin Is Nothing Then Exit Property
  ISubtypesSnapExtension_IsDialogVisible = m_pDockWin.IsVisible
End Property
  
Private Sub ISubtypesSnapExtension_ToggleDialogVisibility()
  If m_pDockWin Is Nothing Then Exit Sub
  m_pDockWin.Show Not m_pDockWin.IsVisible
End Sub
  
Private Property Get ISubtypesSnapExtension_SnapDialogHWnd() As Long
  If m_snapForm Is Nothing Then Exit Property
  ISubtypesSnapExtension_SnapDialogHWnd = m_snapForm.List1.hWnd
End Property

The SnapExtension should be registered to the ESRI Editor Extensions component category. This will allow ArcMap to find the extension, instantiate it, and ensure it receives a reference to the Editor object.

Now the extension is complete, and you can create the remaining objects required.


Creating the SnapDockableWindow

To provide a mechanism for users to turn each SubtypeSnap agent on and off, create a subtype of the DockableWindow abstract class called SnapDockableWindow.


Implementing IDockableWindowDef

In the DockableWindowDef::OnCreate method, use the hook object passed in to find the Editor and, in turn, the SnapExtension editor extension, and store a reference to this extension.

[Visual Basic 6]
Private m_snapExt As SnapAgentVB.ISubtypesSnapExtension
  
...
  
Private Sub IDockableWindowDef_OnCreate(ByVal hook As Object)
  Dim pApp As esriFramework.IApplication
  Set pApp = hook
  
  Dim pUID As New esriSystem.UID
  pUID = "esriEditor.Editor"
  Dim pEditor As esriEditor.IEditor
  Set pEditor = pApp.FindExtensionByCLSID(pUID)
  
  pUID = "SnapAgentVB.SnapExtension"
  Set m_snapExt = pEditor.FindExtension(pUID)
End Sub

Use this reference to return the handle of the Snap Form via the ISubtypesSnapExtension::SnapDialogHWND property from IDockableWindowDef_ChildHWND

[Visual Basic 6]
Private Property Get IDockableWindowDef_ChildHWND() As esriSystem.OLE_HANDLE
  If m_snapExt Is Nothing Then Exit Sub
  IDockableWindowDef_ChildHWND = m_snapExt.SnapDialogHWnd
End Property

Return strings from the Caption and Name properties to identify the dockable window. The Name property will be displayed on the title bar of the dockable window when it is undocked.

The SnapDockableWindow should be registered to the ESRI Mx Dockable Windows component category. This will allow the DockableWindowManager to find this dockable window and, in turn, allow your extension to find the SnapDockableWindow.


Creating the ShowSnapWindow command

The last thing you need to complete this example is a command that can show and hide the SnapDockableWindow. Add a new class to your project called ShowSnapWindow and implement the ICommand interface in that class.


In the ICommand::OnCreate method, store references to the SnapExtension (as you did in IDockableWindowDef::OnCreate).

[Visual Basic 6]
Private m_snapExt As SnapAgentVB.ISubtypesSnapExtension
Private m_pEditor As esriEditor.IEditor
  
...
  
Private Sub ICommand_OnCreate(ByVal hook As Object)
  If Not TypeOf hook Is esriArcMapUI.IMxApplication Then Exit Sub
  Dim pApp As esriFramework.IApplication
  Set pApp = hook
  Dim pDockWinMgr As esriFramework.IDockableWindowManager
  Set pDockWinMgr = hook  ' QI for IDockableWindowManager
  
  Dim pUID As New esriSystem.UID
  pUID = "esriEditor.Editor"
  Set m_pEditor = pApp.FindExtensionByCLSID(pUID)
  pUID = "SnapAgentVB.SnapExtension"
  Set m_snapExt = m_pEditor.FindExtension(pUID)
  
End Sub

When the command is clicked, change the visibility of the SnapDockableWindow by using the ISubtypesSnapExtension::ToggleDialogVisibility method.

[Visual Basic 6]
Private Sub ICommand_OnClick()
  m_snapExt.ToggleDialogVisibility
End Sub

In the Checked property, indicate the current state of the dockable window.

[Visual Basic 6]
Private Property Get ICommand_Checked() As Boolean
  ICommand_Checked = m_snapExt.IsDialogVisible
End Property

Return the Enabled state based on the EditState of the Editor.

[Visual Basic 6]
Private Property Get ICommand_Enabled() As Boolean
  ICommand_Enabled = (m_pEditor.EditState = esriStateEditing)
End Property

The ShowSnapWindow command should be registered to the ESRI Mx Commands component category. This will allow users to add the command to a command bar as required.

Now that all the members of the SubtypesSnap example are complete, compile the component, make sure the classes are registered to their appropriate component categories, and use the example as described in the overview at the beginning of this topic.

 


Back to top

Go to example code

See Also Extending the Editing Framework, About Snap Agents, and About Editor Extensions.