arcpy.mapping.UpdateLayers isn't updating...

579
2
Jump to solution
12-10-2018 08:23 AM
JonSommerville1
New Contributor II

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!

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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()

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

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()
JonSommerville1
New Contributor II

That was it, thank  you very much!

0 Kudos