1

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.

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.