How to identify layer within group in ArcGIS Pro

716
2
Jump to solution
03-09-2021 04:34 AM
anamanvil
New Contributor II

Hi All,

 

I am struggling to identify a layer within a group and create that object for my script.

This would be the script line I follow to create an object for just a 'standard' layer:

road_ln = map_generic.listLayers("Road")[0]

If I were to do the same for a layer within a group layer, I identify the following structure as below

Network/Road

... with Network being the Group Layer and Road the Layer within that specific group.

Following this logic, I then go and try the below without success:

road_ln_grp = map_generic.listLayers("Network/Road")[0]

I have been going through documentations and the community these past days.

Any idea how I am able to do so?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Check the code provided in this thread:

https://community.esri.com/t5/python-questions/listing-layers-in-a-group/td-p/736543 

@FC_Bassonprovided this example:

 

proj = arcpy.mp.ArcGISProject('CURRENT')
m = proj.listMaps()[0]
ml = m.listLayers()
for l in ml:
   if l.isGroupLayer:
      print(l)
      lyrs = l.listLayers()
      for lyr in lyrs:
         print(lyr)

 

 

View solution in original post

0 Kudos
2 Replies
by Anonymous User
Not applicable

Check the code provided in this thread:

https://community.esri.com/t5/python-questions/listing-layers-in-a-group/td-p/736543 

@FC_Bassonprovided this example:

 

proj = arcpy.mp.ArcGISProject('CURRENT')
m = proj.listMaps()[0]
ml = m.listLayers()
for l in ml:
   if l.isGroupLayer:
      print(l)
      lyrs = l.listLayers()
      for lyr in lyrs:
         print(lyr)

 

 

0 Kudos
anamanvil
New Contributor II

Thanks for your prompt reply @Anonymous User This is exactly what I needed 🙂