AnsweredAssumed Answered

Remove Layers

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

Hi  everyone,

i have mxd with 85 layers and i try to remove layers (with arcpy) that don't exist in the current data frame. i using this code:

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

env.workspace = r"C:\Project"
for mxdname in arcpy.ListFiles('*.mxd'):
     print mxdname
     mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
     df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
     for lyr in arcpy.mapping.ListLayers(mxd,"",df):
          if lyr in df.extent == False:
               arcpy.mapping.RemoveLayer(df, lyr)
               print 'RemoveLayer' 
del  mxd

but i get en error:


Traceback (most recent call last):
  File "C:/yaron/shonot/software/gis/tools/YARON_SCRIPTS/", line 15, in <module>
    if lyr in df.extent == False:
TypeError: argument of type 'Extent' is not iterable

i don't know why my code doesn't work.

Thanks for any help.