AnsweredAssumed Answered

Solving my arcpy.updateLayers problem, then looping the solution...

Question asked by AntoineCantinR on Apr 5, 2016
Latest reply on Apr 6, 2016 by AntoineCantinR

Part A: I'm trying to use the code above to update layers in a mxd using a .lyr file. These layers are in a dataframe named "Couches" (there is another dataframe in the mxd). Code comes from this post.

import arcpy.mapping as mmap

mxd = mmap.MapDocument("C:/Users/enclume/Carto/Cartes/UpdateTest/P_5_1.mxd")
DF = mmap.ListDataFrames(mxd, "Couches")[0]
sourcely = mmap.Layer("C:/Users/enclume/Carto/Cartes/Templates/Couches.lyr")
ly = mmap.ListLayers(mxd)[1]
mmap.UpdateLayer(DF, ly, sourcely, False)

 

When I run the code everything seems fine, no error message. But when I open the mxd, nothing has changed. What am I doing wrong?

 

Part B: Once the problem is solved, I would like to loop this code so that it would update all mxd's in a file. How would you proceed to loop it? I saw some stuff here, but I'm far from really understanding how to apply this example to my situation. The person who wrote the code linked above mentioned the glob.glob function to loop it, but I can't find anything about it. Does anyone know how to use it?

If my mxd's folder ("C:/Users/enclume/Carto/Cartes/UpdateTest") contains some subfolders, will the looping function find all the mxd's in the folder and subfolders?

I'm new to arcpy so please be indulgent and precise...

 

Thanks in advance !

Outcomes