How to get the map's selection from the editor


If your edit tool or task needs the map's currently selected features, the easiest way to get these is to use IEditor::EditSelection.

How to use

  1. Paste the code into your VBA Application.
  2. Select some features and run the subroutine.
[VBA]
Public Sub EditSelection()
    Dim pApp As IApplication
    Dim pEditor As IEditor
    Dim pEnumFeat As IEnumFeature
    Dim pFeature As IFeature
    Dim Count As Integer
    Dim pID As New UID
    'Get a handle to the Editor extension
    pID = "esriEditor.Editor"
    Set pApp = Application
    Set pEditor = pApp.FindExtensionByCLSID(pID)
    'Get the selection
    Set pEnumFeat = pEditor.EditSelection
    pEnumFeat.Reset
    'Loop through the selection and perform some action
    For Count = 0 To pEditor.SelectionCount - 1
        Set pFeature = pEnumFeat.Next
        'In this example return the GeometryType
        MsgBox pFeature.Shape.GeometryType
    Next Count
End Sub






Additional Requirements
  • An Edit Session.