I am new to ArcPy, and don't know how to assign different layers to the same lyr file. The layers have "pol" in common. Replacement is a single layer, and so must be walked through the entire document.

import arcpy.mapping as mapping
... mxd = mapping.MapDocument ("CURRENT")
... df = mapping.ListDataFrames (mxd, "Layers") [0]
... updateLayer = mapping.ListLayers (mxd, "Pol_01_002", df) [0]
... sourceLayer = mapping.Layer (r "g: \ Pol01_001.lyr")
... mapping.UpdateLayer (df, updateLayer, sourceLayer, False)

How can I assign a single layer style file to all layers?

1 Answer 1


You need to take a whole list of your layers and iterate it. Try this:

import arcpy.mapping as mapping
mxd = mapping.MapDocument("CURRENT")
df = mapping.ListDataFrames(mxd, "Layers")[0]
updateLayers = mapping.ListLayers(mxd, "Pol*", df)
sourceLayer = mapping.Layer(r"g:\Pol01_001.lyr")
for uL in updateLayers:
   mapping.UpdateLayer(df, uL, sourceLayer, False)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.