I've looked at a number of sources and from what I gather, it seems like the only way I can apply a symbology is to do the following:
- Manually create a layer file that has the symbology I want already applied.
- Apply the symbology from the created feature layer using the arcpy.ApplySymbologyFromLayer_Management function.
This is what I have in code so far to do the above:
mxd = arcpy.mapping.MapDocument(MAP_PATH) data_frame = arcpy.mapping.ListDataFrames(mxd) for layer in arcpy.mapping.ListLayers(mxd): symbol_name = path_to_symbol_layer_file temp_layer_name = layer.name arcpy.MakeFeatureLayer_management( in_features=layer.dataSource, out_layer=temp_layer_name, ) arcpy.ApplySymbologyFromLayer_management( in_layer=temp_layer_name, in_symbology_layer=symbol_name, ) arcpy.mapping.UpdateLayer( data_frame=data_frame, update_layer=layer, source_layer=arcpy.mapping.Layer(temp_layer_name), symbology_only=True, ) mxd.save() del mxd
I'd prefer to keep my symbologies organized in a single
.style file and apply each one directly, without having to create a layer file for it. Is this not possible with
In other words, in pseudo-code, I want something like:
style = arcpy.Style('/path/to/foo.style') mxd = arcpy.mapping.MapDocument('/path/to/bar.mxd') for layer in arcpy.ListLayers(mxd): symbology = arcpy.GetSymbology(style, "custom_symbology_%s" % layer.name) arcpy.ApplySymbology(layer, symbology) mxd.Save() del mxd