How to display selected features in Identify Dialog

3562
3
04-17-2014 03:44 PM
KatieGaut1
New Contributor III
Hello,
    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
0 Kudos
3 Replies
T__WayneWhitley
Frequent Contributor
Hi Katie,
I don't have much time but this was interesting enough that I can at least contribute this:

I think your problem is you are using a method (AddLayerIdentifyPoint) that requires X, Y coordinate value input and your subroutine is called by your statement "DoIdentify(activeView, 300, 100)" which of course show static X, Y coordinates of 300, 100.

But you stated you wanted to load your ID dialog window with your selected features, whatever they may be. Fortunately, you should be able to do this with the method, AddLayerIdentifyOID, if you stick with the same IIdentifyDialog interface (it has been superseded by IIdentifyDialog2). The .NET webhelp:

ArcObjects Library Reference (CartoUI)
IIdentifyDialog Interface
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IIdentifyDialog_Interfac...


Looks like esri samples have commonly demonstrated the AddLayerIdentifyPoint method, including this C# snippet that appears to be basically the equivalent of your posted subroutine:

[C#]
Do Identify Snippet
Performs an identify (via the Identify Dialog) on the layers in the Active View.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Do_Identify_Snippet/0049...

identifyDialog.AddLayerIdentifyPoint(layer, x, y);


As a quick test to confirm you can 'commandeer' an ID window, I did this very short snippet in 10.0 VBA:
Sub test()
Dim pMxDoc As IMxDocument
Dim pActiveView As IActiveView
Dim pIdentifyDialog As IIdentifyDialog
Dim pIdentifyDialogProps As IIdentifyDialogProps
Dim pEnumLayer As IEnumLayer
Dim pLayer As ILayer2

Set pMxDoc = Application.Document
Set pActiveView = pMxDoc.FocusMap
Set pIdentifyDialog = New IdentifyDialog
Set pIdentifyDialogProps = pIdentifyDialog
Set pIdentifyDialog.Map = pMxDoc.FocusMap
Set pIdentifyDialog.Display = pActiveView.ScreenDisplay

pIdentifyDialog.ClearLayers

Set pEnumLayer = pIdentifyDialogProps.Layers

pEnumLayer.Reset
Set pLayer = pEnumLayer.Next

Do While Not pLayer Is Nothing
     pIdentifyDialog.AddLayerIdentifyOID pLayer, 4
     Set pLayer = pEnumLayer.Next
Loop

pIdentifyDialog.Show

End Sub


You should be able to pick this up from here -- notice the change in the loop (highlighted red above), which is actually looping the layers to display any layers with OBJECTID of 4 (I just picked a random one, but you can make a similar subroutine in vb.net to feed in OIDs instead of XY vals). Note that if you have a list of OIDs for a single layer to add to the dialog before moving on to the next pLayer, you can 'nest' a loop to iterate the OIDs per layer so that AddLayerIdentifyOID will effectively add each one.

I didn't think of a way to pass the selected set you say you have, but it's simple enough to get access to the OIDs and pass that list.

Hope that's clear...

Wayne


Note that this "New IdentifyDialog" window is independent of the system Identify window.
0 Kudos
KatieGaut1
New Contributor III
Thanks Wayne!  I'm working on the code now and will post when I have the final code working...or if I have any follow up questions.  Thanks again!

- Katie
0 Kudos
KatieGaut1
New Contributor III
Success - finally!  This was a struggle, and I'm sure there is a classier way, but this is the code that I got working.  The only glitch is that the identify box expands the first layer (so you can see all selected records), but the second layer stays condensed.  You have to manually click the "+" to expand after the script runs.  Any thoughts on that?

Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.CartoUI
Imports ESRI.ArcGIS.Geodatabase

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

    Sub test()
        Dim pMxDoc As IMxDocument
        Dim pActiveView As IActiveView
        Dim pIdentifyDialog As IIdentifyDialog
        Dim pIdentifyDialogProps As IIdentifyDialogProps
        Dim pEnumLayer As IEnumLayer
        Dim pLayer As ILayer2
        Dim pFtrLyr As IFeatureLayer
        Dim pFtrSel As IFeatureSelection
        Dim pFtrCsr As IFeatureCursor
        Dim pFtr As IFeature

        pMxDoc = My.ArcMap.Application.Document
        pActiveView = pMxDoc.FocusMap
        pIdentifyDialog = New IdentifyDialog
        pIdentifyDialogProps = pIdentifyDialog
        pIdentifyDialog.Map = pMxDoc.FocusMap
        pIdentifyDialog.Display = pActiveView.ScreenDisplay

        pIdentifyDialog.ClearLayers()

        pEnumLayer = pIdentifyDialogProps.Layers

        pEnumLayer.Reset()
        pLayer = pEnumLayer.Next

        ' Get a ref to the first layer
        pFtrLyr = pMxDoc.FocusMap.Layer(0)

        ' Get a cursor on the selected features in this layer
        pFtrSel = pFtrLyr
        ' Sets cursor to start at beginning of selected feature
        pFtrSel.SelectionSet.Search(Nothing, False, pFtrCsr)

        ' loop thru selected features and display OID of each

        pFtr = pFtrCsr.NextFeature
        While Not pLayer Is Nothing
            Do While Not pFtr Is Nothing
                'MsgBox("Before pFtr NextFeature Call")
                pIdentifyDialog.AddLayerIdentifyOID(pLayer, pFtr.OID)
                Debug.Print(pFtr.OID)
                pFtr = pFtrCsr.NextFeature
                'MsgBox("End of First Loop")
            Loop
            ' Loop to move through layers and NOT call identify loop unless 
            ' there are selected records.
            pLayer = pEnumLayer.Next
            If Not pLayer Is Nothing Then
                pFtrLyr = pLayer
                pFtrSel = pFtrLyr
                pFtrSel.SelectionSet.Search(Nothing, False, pFtrCsr)
                Debug.Print(pFtrLyr.Name)
                pFtr = pFtrCsr.NextFeature
            End If
        End While
        pIdentifyDialog.Show()
    End Sub

    Public Sub New()

    End Sub

    Protected Overrides Sub OnClick()
        test()
    End Sub

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