I'm trying to create a script that updates layer symbology in other mxds by asking for mxds and asking for the source layer. The script is supposed to iterate through each mxd selected and search for layer names that match the source layer. No error is given and it prints my message at the end but when looking at the mxd that was supposed to be updated, the symbol doesn't change.
import arcpy, string, os
mxdSelection = arcpy.GetParameterAsText(0)
sourceLyr = arcpy.GetParameter(1)
mxdString = mxdSelection.split(";")
for each in mxdString:
mxd = arcpy.mapping.MapDocument(each)
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == sourceLyr.name:
arcpy.mapping.UpdateLayer(df, lyr, sourceLyr, True)
arcpy.AddMessage(lyr.name + " under the " + df.name + " data frame has been updated.")
This is what appears in the "successful" message:
When I open the "updated" mxd, symbols are the same.
Thanks for reading and any advice given!
Solved! Go to Solution.
Hi Jon,
Doesn't look like you're saving the MXD. Try adding the following at the end of your script:
if lyr.name == sourceLyr.name:
arcpy.mapping.UpdateLayer(df, lyr, sourceLyr, True)
arcpy.AddMessage(lyr.name + " under the " + df.name + " data frame has been updated.")
mxd.save()
Hi Jon,
Doesn't look like you're saving the MXD. Try adding the following at the end of your script:
if lyr.name == sourceLyr.name:
arcpy.mapping.UpdateLayer(df, lyr, sourceLyr, True)
arcpy.AddMessage(lyr.name + " under the " + df.name + " data frame has been updated.")
mxd.save()
That was it, thank you very much!