I am working on ArcMap 10.3 and I have a map with 50 layers in it.
I am trying to check if layers are in a data frame.
Unlike How to check if layers in a dataframe with Arcpy, I want to define the area to the current data frame.
My code is:
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") data_frame = df for lyr in arcpy.mapping.ListLayers(mxd,"",df): if lyr in data_frame == False: arcpy.mapping.RemoveLayer(df, lyr) print lyr mxd.save() del mxd
and I get:
>>> Project.mxd >>>
but no layers have been removed.