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'
mxd.save()
del mxd
but i get en error:
>>>
Project.mxd
Traceback (most recent call last):
File "C:/yaron/shonot/software/gis/tools/YARON_SCRIPTS/aaaaaaaaaaaaaa.py", 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.