AnsweredAssumed Answered

Removing a layer from multiple mxds

Question asked by kltrooper on Mar 14, 2013
Latest reply on Mar 15, 2013 by kltrooper
I attempted to modify a sample code to remove just one layer from one of the two data frames, "Primary", I have in multiple mxds, all stored in the same folder.  This code runs, but does not actually remove the layer, "Dams", from the two text mxds, stored in the folder, RemoveLayers1.  I've specified upper, considering Dams starts with a cap D, but maybe it requires a diff command when caps are mixed with lower case.
I'm hoping someone can see what I'm missing. I would expect the code to provide an error message; not just fail to remove the layer.

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 == 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    #