FeatureLayer in GroupLayer

2319
3
Jump to solution
07-17-2013 02:01 AM
MickeyO_Neil
New Contributor III
Hi,

I would like to Export a FeaturLayer which is in several Group Layers into a lyr-File.
The Problem is: The Grouplayers have to be exported, too, so the structure of the Layers stayes the same.
But I can't find a way how to get to know if a FeatureLayer is within a GroupLayer, or if a GroupLayer is in another GroupLayer.

And if i loop through all GroupLayers I don't know which one is at the top.

Any idea, how to get this infos?

Thanks
M.
0 Kudos
1 Solution

Accepted Solutions
MickeyO_Neil
New Contributor III
Found it!

You can cast IGroupLayer into ICompositeLayer.

View solution in original post

0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
Mickey,

I don't believe there is a method or property that returns the answer to "does this layer belong to a group layer, if so which".

You would need to create a recursive procedure that searches the layers and traverse down the tree of layers testing the type of layers you are finding.

Below is a bit of VBA that shows you how to test the type of layer found. You need to create a recursive procedure around this logic.

Public Sub test()    
    Dim pMXDocument As IMxDocument
    Set pMXDocument = ThisDocument
    Dim pMap As IMap
    Set pMap = pMXDocument.FocusMap
    Dim pEnumLayer As IEnumLayer
    Set pEnumLayer = pMap.Layers(Nothing, True)
    Dim pLayer As ILayer
    Set pLayer = pEnumLayer.Next
    Do While Not pLayer Is Nothing
        If TypeOf pLayer Is IGroupLayerayer Then
            Debug.Print "GroupLayerayer = " & pLayer.Name
            ' Do a recursive search here
        ElseIf TypeOf pLayer Is IGeoFeatureLayer Then
            Debug.Print "FeatureLayer = " & pLayer.Name
        End If
        Set pLayer = pEnumLayer.Next
    Loop
End Sub


Duncan
0 Kudos
MickeyO_Neil
New Contributor III
Hi Duncan,

but for a recursive procedure I would need a List or a IEnumLayer Object of all Layers which are in the GroupLayer.
I can't find this function.
0 Kudos
MickeyO_Neil
New Contributor III
Found it!

You can cast IGroupLayer into ICompositeLayer.
0 Kudos