Hello,
The following script works perfectly to update all mxds contained in one folder using a unique .lyr file as a reference to all layers (in groups and subgroups). All mxds have the same TOC composition, but the visibility of each layer depend of the mxd. My problem is that when I run the "update script", the .lyr file apply his parameter to the layers so it turns them OFF. The .lyr file contains only OFF layers because, as I said, the visibility of every layer is different in each map project.
So I would love to find a way to integrate a few more lines of code in the script so it would list the layers visibility parameter (for every layers in the mxd), then do the update, finally toggle back ON the layers that were ON initially using the list.
I found something, but I can't find a way to integrate it in the "update script" (http://gis.stackexchange.com/a/158476/69986).
Here the "update script":
import arcpy
import os
MxdFolderPath = arcpy.GetParameterAsText(0)
if MxdFolderPath == '#' or not MxdFolderPath:
MxdFolderPath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Mise_a_jour/Test"
MxdCount = 0
sourcelypath = arcpy.GetParameterAsText(1)
if sourcelypath == '#' or not sourcelypath:
sourcelypath = "//10.13.77.8/MRC_doc/20_Territoires/20-4000_Schema_Amen_Dev/20-4100_Planification/20-4120_Projet_SAD/20-4121_Projet_SAD/Y_Cartographie/A_Planches/Fichiers .lyr/Autres formats/Couches.lyr" # reference .lyr file
sourcely = arcpy.mapping.Layer(sourcelypath)
arcpy.env.workspace = MxdFolderPath
arcpy.AddMessage(" MXD PROCESSING")
mxdList = arcpy.ListFiles("*.mxd")
Mxdlen = len(mxdList)
if Mxdlen == 0:
arcpy.AddMessage(" There are no mxd in: " + str(MxdFolderPath))
else:
arcpy.AddMessage(" There are " + str(Mxdlen) + " mxd in: " + str(MxdFolderPath))
for mxd in mxdList:
MxdCount = (MxdCount + 1)
MxdPPath = os.path.join(MxdFolderPath, mxd)
processingmxd = arcpy.mapping.MapDocument(MxdPPath)
arcpy.AddMessage(" Mxd: " + str(MxdCount) + " :" + str(mxd))
dflist = arcpy.mapping.ListDataFrames(processingmxd, "Couches_DF") # Dataframe
for df in dflist:
arcpy.AddMessage(" df: " + str(df.name))
layers = arcpy.mapping.ListLayers(processingmxd, "Couches", df) # layers called Couches
for layer in layers:
arcpy.AddMessage(" Layer: " + str(layer))
arcpy.mapping.UpdateLayer(df, layer, sourcely, False)
arcpy.AddMessage(" Layer Updated")
processingmxd.save()
arcpy.AddMessage(" ")
arcpy.AddMessage(" End")
Can anyone help? Thanks in advance!