AnsweredAssumed Answered

Remove group layer with arcpy

Question asked by yaron148 on Apr 14, 2015
Latest reply on Apr 14, 2015 by yaron148


i try to remove a group layer with arcpy for several mxd's with this code:


import arcpy,os,sys
import arcpy.mapping
from arcpy import env

env.workspace = r"D:\PROJECTS\atar_ashpa_depo\gis"
for mxdname in arcpy.ListFiles("*.mxd"):
    print mxdname # print list of mxd's in the folder
    mxd = arcpy.mapping.MapDocument(r"D:\PROJECTS\atar_ashpa_depo\gis\\" + mxdname)
    dfList = arcpy.mapping.ListDataFrames(mxd, "*")
    for df in dfList:
        for lyr in arcpy.mapping.ListLayers(mxd, "", df):
            if == "segment-BL.dwg Group Layer":
                arcpy.mapping.RemoveLayer(df, lyr)
                print 'RemoveLayer 3'
del mxd

but get en error:


land use map

Traceback (most recent call last):
  File "C:\yaron\shonot\software\gis\tools\YARON_SCRIPTS\RemoveLayer by name with 2 df option", line 35, in <module>
    if == "segment-BL.dwg Group Layer":
AttributeError: 'Layer' object has no attribute 'GroupLayer'

thanks for any help