2

I have a number of layers that I want to manipulate with ArcPy. On my ArcGIS Pro map I have them under a group layer.

To deal with them, I have been picking them by name as follows:

for theLayer in theMaps.listLayers():
 # print (theLayer.name)
 if theLayer.supports("ISFEATURELAYER"):
 if theLayer.isFeatureLayer and theLayer.name[:10] == "....":

but I'm wondering if I cannot just reference them by group?

Parsing the name creates an admin overhead to rename the sources first.

Something like

if theLayer.belongsToGroupLayer("MyGroupLayerName"):

or

if theLayer.parentlayer == "MyGroupLayerName":

The Layer class documentation does not offer any solution to this.

Lilium
1,0651 gold badge8 silver badges17 bronze badges
asked Mar 29, 2021 at 22:23

1 Answer 1

3

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

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

enter image description here

answered Apr 27, 2021 at 5:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.