Expanding on my previous question Remove layers using python- path orientation, i try to remove layers from mxd's (in ArcMap 10.3, Python 2.7.8), that don't appear in the data frame.
The layers located in different disk drivers and in different folders and sub folders and each layer has different path orientation (right to left- different language from English). Only the MXD's located in "D:\desktop\Project" I using this code:
import arcpy,os from arcpy import env env.workspace = r"D:\desktop\Project" for mxdname in arcpy.ListFiles('*.mxd'): print mxdname mxd = arcpy.mapping.MapDocument(os.path.join(env.workspace, mxdname)) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if lyr.getExtent() != None: if df.extent.disjoint(lyr.getExtent()): arcpy.mapping.RemoveLayer(df, lyr) print u'Removed ' + unicode(lyr) mxd.save() del mxd When i run the code i get only the name project and no filtering layers is done:
>>> project.mxd >>>
أكثر...
The layers located in different disk drivers and in different folders and sub folders and each layer has different path orientation (right to left- different language from English). Only the MXD's located in "D:\desktop\Project" I using this code:
import arcpy,os from arcpy import env env.workspace = r"D:\desktop\Project" for mxdname in arcpy.ListFiles('*.mxd'): print mxdname mxd = arcpy.mapping.MapDocument(os.path.join(env.workspace, mxdname)) df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for lyr in arcpy.mapping.ListLayers(mxd, "" ,df): if lyr.getExtent() != None: if df.extent.disjoint(lyr.getExtent()): arcpy.mapping.RemoveLayer(df, lyr) print u'Removed ' + unicode(lyr) mxd.save() del mxd When i run the code i get only the name project and no filtering layers is done:
>>> project.mxd >>>
أكثر...