AnsweredAssumed Answered

Updating a layer to multiple MXDs

Question asked by kltrooper on Mar 15, 2013
Latest reply on Mar 21, 2013 by Wayne_Whitley
I'm frustrated that the ESRI sample scripts do not allow updating multiple mxds. In the real world why would someone go to the trouble to modify a sample script that just updates one mxd?  Would it not just be faster to make the change to the single mxd?  Every scenrio I encounter requires updating a huge no of mxds.
Here's a script  that works, on our server, to remove multiple layers from multiple mxds. Could someone, please, tell me how to mod it to update layer. I tried modifying the sample layer available from esri and couldn't even get close. I just want to change the color symbology of the dams layer, for all of the mxds stored in the target layers folder, with the source layer, Dams, archived in an "update layers" folder on my server
Ken


[CODE]

import arcpy
import os
import glob
mxds_path = r'S:\\Users Shared\\LOpperman\\Town Scale MXDs\\MXDs\\targetlayers\\'
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.lower() == layer_name:
        print 'Remove layer ' + layer_name
        arcpy.mapping.RemoveLayer(df, lyr)
  #copyFile = mxds_path + r"NEW_" +
  #print copyFile
  mxd.save()
 

#for mxd_name in mxds:
  #mxd = arcpy.mapping.MapDocument(mxds_path + mxd_name)
  #print 'removing layer for ' + mxd_name
 
#  mxd.save() 
[/COD]

Outcomes