Solved! Go to Solution.
import arcpy, os, glob mxds_path = r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\MXDs\\targetlayers\\' layer_name = r'dams' data_frame = r'Primary' # Say you want to replace the 'Dams' layer with an updated dams layer saved to a layer file. # ...in this case a 'source' layer object was created using lyr file stored outside the map document: # (The network folder 'LYRs' is fictitious...replace this pathname accordingly.) sourceLayer = arcpy.mapping.Layer(r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\LYRs\\Dams.lyr") for infile in glob.glob(os.path.join( mxds_path, "*.mxd" )): mxd = arcpy.mapping.MapDocument(infile) print "replacing Dams layer from " + infile for df in arcpy.mapping.ListDataFrames(mxd, data_frame): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name.lower() == layer_name: print 'Replace layer ' + layer_name # 'wholesale' replace (not just the symbology) arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, False) mxd.save() del mxd print 'finished!'
import arcpy, os, glob mxds_path = r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\MXDs\\targetlayers\\' layer_name = r'dams' data_frame = r'Primary' # Say you want to replace the 'Dams' layer with an updated dams layer saved to a layer file. # ...in this case a 'source' layer object was created using lyr file stored outside the map document: # (The network folder 'LYRs' is fictitious...replace this pathname accordingly.) sourceLayer = arcpy.mapping.Layer(r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\LYRs\\Dams.lyr") for infile in glob.glob(os.path.join( mxds_path, "*.mxd" )): mxd = arcpy.mapping.MapDocument(infile) print "replacing Dams layer from " + infile for df in arcpy.mapping.ListDataFrames(mxd, data_frame): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name.lower() == layer_name: print 'Replace layer ' + layer_name # 'wholesale' replace (not just the symbology) arcpy.mapping.UpdateLayer(df, lyr, sourceLayer, False) mxd.save() del mxd print 'finished!'
sourceLayer = arcpy.mapping.Layer(r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\LYRs\\Dams.lyr')