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?
Solved! Go to Solution.
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)
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)
Thanks for your prompt reply @Anonymous User This is exactly what I needed 🙂