I have multiple layers in ArcMap that I want to import a symbology for from a layer file. The code I have is as follows:
import arcpy from arcpy import env # Reference current MXD and dataframe. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers") layers = arcpy.mapping.ListLayers(mxd,"",df) # Layer file symbology to be imported is in. in_symbology_layer = arcpy.mapping.Layer("C:\LayerStyles\LayerFile.lyr") # Layer to receive imported symbology. in_layer = arcpy.mapping.ListLayers(mxd, "", df) # For loop to import symbology to all layers in current MXD. for lyr in layers: try: arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer) except: print "Failed to import symbology for: " +lyr.name # Refreshes Table of Contents. arcpy.RefreshTOC()
The code seems to work in parts, as the output I get is:
"Failed to import symbology for: Layer1
"Failed to import symbology for: Layer2
"Failed to import symbology for: Layer3..."
For loops are my Achilles Heel so any assistance would be greatly appreciated!