import arcpy import os import glob mxds_path = r'C:\\Temp\\removelayers1\\' layer_name = r'Dams' data_frame = r'Primary' layers = [] mxds = [] for infile in glob.glob(os.path.join( mxds_path, "*.mxd" )): mxd = arcpy.mapping.MapDocument(infile) print "removing Dams layer from " + infile for df in arcpy.mapping.ListDataFrames(mxd, data_frame): for lyr in arcpy.mapping.ListLayers(mxd, "", df): #print lyr if lyr.name.upper() == layer_name: print 'Remove layer ' + layer_name arcpy.mapping.RemoveLayer(df, lyr) #for mxd_name in mxds: #mxd = arcpy.mapping.MapDocument(mxds_path + mxd_name) #print 'removing layer for ' + mxd_name # mxd.save()
Solved! Go to Solution.
>>> someText = 'IamAlayer' >>> print someText.upper() IAMALAYER >>> print someText.lower() iamalayer >>>
>>> if layer_name.lower() == 'dams': print 'yes, we have a match - go ahead with the rest code block.' yes, we have a match - go ahead with the rest code block. >>> if layer_name.upper() == 'DAMS': print 'yes, we have a match - again, proceed...' yes, we have a match - again, proceed... >>> if layer_name.lower() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>> >>> if layer_name.upper() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>>
>>> someText = 'IamAlayer' >>> print someText.upper() IAMALAYER >>> print someText.lower() iamalayer >>>
>>> if layer_name.lower() == 'dams': print 'yes, we have a match - go ahead with the rest code block.' yes, we have a match - go ahead with the rest code block. >>> if layer_name.upper() == 'DAMS': print 'yes, we have a match - again, proceed...' yes, we have a match - again, proceed... >>> if layer_name.lower() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>> >>> if layer_name.upper() == 'Dams': print 'go go go proceed with the code block...' else: print 'no way....we do not agree - halt this block!' no way....we do not agree - halt this block! >>>
import arcpy, os, glob mxds_path = r'C:\Temp\removelayers1' layer_name = 'DAMS' for infile in glob.glob(os.path.join( mxds_path, "*.mxd")): mxd = arcpy.mapping.MapDocument(infile) for df in arcpy.mapping.ListDataFrames(mxd, ""): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name.upper() == layer_name: arcpy.mapping.RemoveLayer(df, lyr) mxd.save()