m.cain

Making Group Layer in different Data Frames visible through a VBA form

Discussion created by m.cain on Mar 19, 2012
Hello,

I am in the process of creating a form that will turn on/off particular layers in several data frames in my map (as well as change various title, figure options in Layout View).

I was hoping to use something like this (where all the items have been declared before hand):

Set pLayer = pMaps.Item(0).Layer(2)
pLayer.Visible = False


In this case:
- Item(0): 1st data frame
- Layer(2): 3rd layer within said data frame

If the 3rd item in my data frame is actually a Group Layer with several layers within, will Layer(2) refer to the Group Layer or something else entirely? I would like the Group Layer to be visible/or not.

Thanks for your guidance.

P.S. Complete code below:

-----

Private Sub Btn1_Click()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pMaps As IMaps
Set pMaps = pMxDoc.Maps

Dim pLayer As ILayer
Dim pMap As IMap
Dim pActiveView As IActiveView

Set pMxDoc = Application.Document
'Check ArcMap is in layout view
If Not pMxDoc.ActiveView Is pMxDoc.PageLayout Then Exit Sub
Set pActiveView = pMxDoc.PageLayout

'set text boxes
Dim pPageLayout As IPageLayout
Dim pCont As IGraphicsContainer
Dim pElement As IElement
Dim pTextElement As ITextElement
Set pPageLayout = pMxDoc.PageLayout
Set pCont = pPageLayout
pCont.Reset
For i = 1 To 45
    
    Set pElement = pCont.Next
    
    If TypeOf pElement Is ITextElement Then
        Dim pElementProps As IElementProperties
        Set pElementProps = pElement
    
        'title
        If pElementProps.Name = "Title" Then
            Set pTextElement = pElement
            pTextElement.Text = "<bol>My Title</bol>"
        End If
    
        'figure number
        If pElementProps.Name = "Fignum" Then
            Set pTextElement = pElement
            pTextElement.Text = "1"
        End If
    
    End If

'MsgBox pElementProps.Name
Next i

'set layers
    'Data Frame 1
    Set pLayer = pMaps.Item(0).Layer(0) 'First layer
    pLayer.Visible = True
    Set pLayer = pMaps.Item(0).Layer(1) 'Second layer
    pLayer.Visible = True
    Set pLayer = pMaps.Item(0).Layer(2) 'Third layer
    pLayer.Visible = True
    Set pLayer = pMaps.Item(0).Layer(3) 'Fourth layer
    pLayer.Visible = False
    Set pLayer = pMaps.Item(0).Layer(4) 'Fifth layer
    pLayer.Visible = False

    'Data Frame 2
    Set pLayer = pMaps.Item(1).Layer(0) 'First layer
    pLayer.Visible = True
    Set pLayer = pMaps.Item(1).Layer(1) 'Second layer
    pLayer.Visible = False
    Set pLayer = pMaps.Item(1).Layer(2) 'Third layer
    pLayer.Visible = False
    Set pLayer = pMaps.Item(1).Layer(3) 'Fourth layer
    pLayer.Visible = True

'refresh
pMxDoc.ActiveView.Refresh
pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
pMxDoc.UpdateContents
Set pMxDoc.ActiveView = pMxDoc.FocusMap
Set pMxDoc.ActiveView = pMxDoc.PageLayout

End Sub

Outcomes