You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects Visual Basic for Application (VBA) forum

Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Hailiang Shen Aug 17, 2009
Re: Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Chirag Danech Aug 17, 2009
Re: Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Chirag Danech Aug 17, 2009
Re: Referencing Layers   Jonathan Bird Aug 17, 2009
Re: Referencing Layers   Chirag Danech Aug 18, 2009
Re: Referencing Layers   Jonathan Bird Aug 19, 2009
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message Hello,

Is there a way to reference a group name of layers rather than a specific layer? If the group was always to be 3rd down the TOC could I reference 'layer' 3 even though it's not a single layer?

What I have at present is the code below and the screenshot on the left of the attachment. What I will need to reference, or work around, is referenceing a selection in one of the layers under 'blank schemeing' on the right screen shot of the attachment.

Many thanks in advance for any help.

Jon 
 
Private Sub UIButtonControl1_Click()

    Dim pEditor As IEditor
    Dim pID As New UID
    Dim pMxDoc As IMxDocument
    Dim pMap As IMap
    Dim pActiveView As IActiveView
    Dim pFeatureLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim LayerCount As Integer
    Dim pFeatureSelection As IFeatureSelection
    Dim pQueryFilter As IQueryFilter
    Dim i As Integer
    Dim player As ILayer
    
    Set pMxDoc = Application.Document
    Set pMap = pMxDoc.FocusMap
    pID = "esriCore.Editor"
  
    Set pEditor = Application.FindExtensionByCLSID(pID)
    Set pActiveView = pMap
    
    For i = 0 To pMap.LayerCount
    
    If pMap.Layer(i).Name = "Blank Scheming" Then
    Set player = pMap.Layer(i)
    Exit For
    End If
    Next i
 
  layer selection.doc (opens in new window)
 
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message Is having a wildcard possible? Somethinkg like ...

If pMap.Layer(i).Name = "Blank Scheming" & "*" Then
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message I can't get that to work, I then thougth perhaps this might work ...

If (pMap.Layer(i).Name = "Blank Scheming1") or (pMap.Layer(i).Name = "Blank Scheming2") Then


but it appears to ignore all but the first one. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Hailiang Shen 
Date Aug 17, 2009 
Message Reference certain group of layers:
http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriCarto/IMap_Layers.htm

On comparing the strings, try "like". e.g.,
if s like "b*" then
' do sth
end if 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message I didn't that way would use the group as a whole, but just individual layers inside the group. I need a way to use the selection of any of the layers i the group. They could be ungrouped but then it would need to use any of the 5 layers which would be no different to the rest of the TOC spine. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Chirag Danech 
Date Aug 17, 2009 
Message Check it out this piece of code to point to specific layer under specific group. 
 
Dim pCompositeLayer As ICompositeLayer
For i = 0 To pMap.LayerCount - 1
        If TypeOf pMap.Layer(i) Is ICompositeLayer Then
            If pMap.Layer(i).name = "Blank Scheming" Then
                Set pCompositeLayer = pMap.Layer(i)
                Set pLayer = pCompositeLayer.Layer(2) ' It will point to third layer of that group
            End If
        End If
    Next
 
  Chirag...
GIS Consultant
chirag.danech@gmail.com
LinkedIn : http://www.linkedin.com/in/arcobjectsdeveloper
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message That might be as close as I'm going to get. Is there no way to treat the group as a layer in terms of the selections within it. What my code does is copy a single selection from the blank scheming layer to the actual data register layer. However now I find in the live GIS there is actually a group, containing 6 layers of blank scheming each covering different scales, as shown in the right side of the attachment. Any ideas welcomed, otherwise I'll click this solved button. Thanks for your time. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Chirag Danech 
Date Aug 17, 2009 
Message You can access selected layer via...

pMxDoc.SelectedLayer.name

In that case you wont required to loop through all layers..if any layer or any layer under any group selected, then it will return you the instance of that layer. 
  Chirag...
GIS Consultant
chirag.danech@gmail.com
LinkedIn : http://www.linkedin.com/in/arcobjectsdeveloper
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 17, 2009 
Message Do you have to state the name or is that just looking literally for the selected layer? 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Chirag Danech 
Date Aug 18, 2009 
Message You wont required to state the name.It was just for your reference if you wanna double check. 
  Chirag...
GIS Consultant
chirag.danech@gmail.com
LinkedIn : http://www.linkedin.com/in/arcobjectsdeveloper
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Referencing Layers 
Author Jonathan Bird 
Date Aug 19, 2009 
Message Many thanks. In the end I have made a form where the user choses which layer to get the cell from, and their choice goes into ...

If pMap.Layer(i).name = form.combo.text then

Seems to do the job and creates a level of error checking.