AnsweredAssumed Answered

Add layer inside group layer that is inside a group layer

Question asked by ant.calatayud on Aug 7, 2015
Latest reply on Aug 7, 2015 by ant.calatayud



It might be a simple question/solution, but I can't find the way to make my arcpy code works....


I have a layer that I need to add inside a group, that is inside a group already:




          -NEW LAYER


-Group 2.


My code is more and less like this:

for layer in layers:

     if layer.longName == Group1+ "\\" + SubGroup1:

          print("------ layer goes here-------")

          targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group1\SubGroup1", df)[0]

          arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, spatialLayer, "AUTO_ARRANGE")



          print ("not here")


Where I wrote "Group1\SubGroup1" I tried: "Group1\\SubGroup1"; "Group1/SubGroup1", but I'm always getting the same error:


targetGroupLayer = arcpy.mapping.ListLayers(mxd, "Group1\SubGroup1", df)[0]

IndexError: list index out of range



Any ideas how to get the subgroup inside the group??


Many thanks!!!