English

How To: Flash features in ArcMap using ArcObjects

Summary

This document contains an ArcObjects code sample that shows how to programmatically flash features in ArcMap.

Procedure

  1. Open ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument, then right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer

    Note:
    Code in the project's ThisDocument code module only runs in the current map document. To store the code in all map documents, open the Normal.mxt ThisDocument code module instead.

  4. Paste the following code into the code module.

    Code:
    Option Explicit
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Public Sub LoopThruFeaturesAndFlash()

    Dim pFeatLyr As IFeatureLayer
    Dim pMap As IMap
    Dim pDoc As IMxDocument
    Set pDoc = Document
    Set pMap = pDoc.FocusMap

    'Get the selected features from the map.
    Dim pEnumFeat As IEnumFeature
    Dim pFeat As IFeature
    Set pEnumFeat = pMap.FeatureSelection
    Set pFeat = pEnumFeat.Next
    Do Until pFeat Is Nothing
    FlashFeature pFeat, pDoc
    Set pFeat = pEnumFeat.Next
    Loop

    End Sub

    Public Sub FlashFeature(pFeature As IFeature, pMxDoc As IMxDocument)

    ' Start drawing on screen.
    pMxDoc.ActiveView.ScreenDisplay.StartDrawing 0, esriNoScreenCache

    ' Switch functions based on Geometry type.
    Select Case pFeature.Shape.GeometryType
    Case esriGeometryPolyline
    FlashLine pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape
    Case esriGeometryPolygon
    FlashPolygon pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape
    Case esriGeometryPoint
    FlashPoint pMxDoc.ActiveView.ScreenDisplay, pFeature.Shape
    End Select

    ' Finish drawing on screen.
    pMxDoc.ActiveView.ScreenDisplay.FinishDrawing
    End Sub
    Private Sub FlashLine(pDisplay As IScreenDisplay, pGeometry As IGeometry)
    Dim pLineSymbol As ISimpleLineSymbol
    Dim pSymbol As ISymbol
    Dim pRGBColor As IRgbColor

    Set pLineSymbol = New SimpleLineSymbol
    pLineSymbol.Width = 4

    Set pRGBColor = New RgbColor
    pRGBColor.Green = 128

    Set pSymbol = pLineSymbol
    pSymbol.ROP2 = esriROPNotXOrPen

    pDisplay.SetSymbol pLineSymbol
    pDisplay.DrawPolyline pGeometry
    Sleep 300
    pDisplay.DrawPolyline pGeometry
    End Sub

    Private Sub FlashPolygon(pDisplay As IScreenDisplay, pGeometry As IGeometry)
    Dim pFillSymbol As ISimpleFillSymbol
    Dim pSymbol As ISymbol
    Dim pRGBColor As IRgbColor

    Set pFillSymbol = New SimpleFillSymbol
    pFillSymbol.Outline = Nothing

    Set pRGBColor = New RgbColor
    pRGBColor.Green = 128

    Set pSymbol = pFillSymbol
    pSymbol.ROP2 = esriROPNotXOrPen

    pDisplay.SetSymbol pFillSymbol
    pDisplay.DrawPolygon pGeometry
    Sleep 300
    pDisplay.DrawPolygon pGeometry
    End Sub

    Private Sub FlashPoint(pDisplay As IScreenDisplay, pGeometry As IGeometry)
    Dim pMarkerSymbol As ISimpleMarkerSymbol
    Dim pSymbol As ISymbol
    Dim pRGBColor As IRgbColor

    Set pMarkerSymbol = New SimpleMarkerSymbol
    pMarkerSymbol.Style = esriSMSCircle

    Set pRGBColor = New RgbColor
    pRGBColor.Green = 128

    Set pSymbol = pMarkerSymbol
    pSymbol.ROP2 = esriROPNotXOrPen

    pDisplay.SetSymbol pMarkerSymbol
    pDisplay.DrawPoint pGeometry
    Sleep 300
    pDisplay.DrawPoint pGeometry
    End Sub

  5. Close the Visual Basic Editor.
  6. Add data to ArcMap.
  7. Select one or more features.
  8. Run the LoopthruFeaturesandFlash subroutine.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.