0

I'm brand new to ArcObjects SDKs and am struggling. I have a Python Add-in performing a query to select records (works great)and now trying to call the identify dialog via an .NET addin button that displays the identify dialog box to show attributes of the selected records. Below is the code I have at this point. I currently have the identify dialog displaying, but no records appearing. I know I need to input the selected records somewhere....but not sure where. Any thoughts would be appreciated. (I'm using Visual Studio/Microsoft Visual Basic 2010 and ArcGIS 10.2.1)

Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto

Public Class Identify_Button
Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Dim pMxDoc As IMxDocument
Dim activeView As IMap

Public Sub DoIdentify(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal x As System.Int32, ByVal y As System.Int32)
    pMxDoc = My.ArcMap.Application.Document
    activeView = pMxDoc.FocusMap
    If activeView Is Nothing Then
        Return
    End If

    Dim map As ESRI.ArcGIS.Carto.IMap = activeView.FocusMap
    Dim identifyDialog As ESRI.ArcGIS.CartoUI.IIdentifyDialog = New ESRI.ArcGIS.CartoUI.IdentifyDialogClass
    identifyDialog.Map = map

    'Clear the dialog on each mouse click
    identifyDialog.ClearLayers()
    Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay = activeView.ScreenDisplay

    Dim display As ESRI.ArcGIS.Display.IDisplay = screenDisplay ' Implicit Cast
    identifyDialog.Display = display

    Dim identifyDialogProps As ESRI.ArcGIS.CartoUI.IIdentifyDialogProps = CType(identifyDialog, ESRI.ArcGIS.CartoUI.IIdentifyDialogProps) ' Explicit Cast
    Dim enumLayer As ESRI.ArcGIS.Carto.IEnumLayer = identifyDialogProps.Layers
    enumLayer.Reset()

    Dim layer As ESRI.ArcGIS.Carto.ILayer = enumLayer.Next

    Do While Not (layer Is Nothing)
        identifyDialog.AddLayerIdentifyPoint(layer, x, y)
        layer = enumLayer.Next()
    Loop

    identifyDialog.Show()

End Sub
Public Sub New()

End Sub

Protected Overrides Sub OnClick()
    DoIdentify(activeView, 300, 100)
End Sub

Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing
End Sub

End Class

1 Answers1

0

Give the code below a try. This is executed from the OnClick event from an ArcMap command button that Inherits from BaseCommand. It displays the selected features in the map in the identifyDialog just as you were needing it to except I used AddLayerIdentifyOID() instead of AddLayerIdentifyPoint() although both should work.

    Public Overrides Sub OnClick()
    'VBTest.OnClick implementation
    Try
        Dim mxDoc As IMxDocument = m_application.Document
        Dim map As ESRI.ArcGIS.Carto.IMap = mxDoc.FocusMap
        Dim layer As ESRI.ArcGIS.Carto.ILayer
        Dim flayer As ESRI.ArcGIS.Carto.IFeatureLayer
        Dim featSelection As ESRI.ArcGIS.Carto.MapSelection = map.FeatureSelection
        Dim feat As ESRI.ArcGIS.Geodatabase.IFeature = featSelection.Next()
        Dim count As Int16 = 0

        While feat IsNot Nothing
            count += 1 ' flag for clearing layers
            flayer = New ESRI.ArcGIS.Carto.FeatureLayer()
            flayer.FeatureClass = feat.Class
            layer = flayer

            DoIdentify(layer, feat.OID, (count = 1))

            feat = featSelection.Next()
        End While

    Catch ex As Exception
        ' handle error
        MsgBox("Error: " + ex.Message)
    End Try

End Sub

Private Sub DoIdentify(ByVal layer As ESRI.ArcGIS.Carto.ILayer, ByVal OID As Int32, Optional ByVal clearLayers As Boolean = True)

    If layer Is Nothing Or OID <= 0 Then
        Return
    End If

    Dim pMxDoc As IMxDocument = m_application.Document
    Dim activeView As ESRI.ArcGIS.Carto.IActiveView = pMxDoc.ActiveView
    Dim map As ESRI.ArcGIS.Carto.IMap = activeView.FocusMap
    Dim identifyDialog As ESRI.ArcGIS.CartoUI.IIdentifyDialog = New ESRI.ArcGIS.CartoUI.IdentifyDialogClass()
    Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay = activeView.ScreenDisplay
    Dim display As ESRI.ArcGIS.Display.IDisplay = screenDisplay

    identifyDialog.Map = map ' REQUIRED
    identifyDialog.Display = display ' REQUIRED

    ' Clear the dialog
    If clearLayers Then
        identifyDialog.ClearLayers()
    End If

    ' Add our selected feature to the dialog
    identifyDialog.AddLayerIdentifyOID(layer, OID)

    ' Show the dialog
    identifyDialog.Show()

End Sub
Tim Sexton
  • 188
  • 8