HOW TO
The symbology property of a feature or a layer is a read-only property unless the symbology type is Graduated Colors, Graduated Symbols, Raster Classified, or Unique Values. Therefore, if the symbology type does not fall in any of these four categories, the symbology property cannot be modified directly. It can only be modified using a preexisting .lyr file or a arcpy layer object that has the desired symbology.
Note: To access the symbology property of a feature or raster, a layer object must be created either using the arcpy.mapping module or Make Feature Layer (Data Management).
This article describes two ways to apply symbology from an existing layer file, using the Layer object, or using the Apply Symbology From Layer geoprocessing tool.
import arcpy mxd = arcpy.mapping.MapDocument(r'C:\temp\sample.mxd') df = arcpy.mapping.ListDataFrames(mxd, "Counties")[0] updateLayer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0] sourceLayer = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr") arcpy.mapping.UpdateLayer(df,updateLayer,sourceLayer, symbology_only = True)
Note: If the symbology_only property in the UpdateLayer function is set to True, only the layer's symbology is updated.
import arcpy mxd = arcpy.mapping.MapDocument(r'C:\temp\sample.mxd') df = arcpy.mapping.ListDataFrames(mxd, "Counties")[0] in_layer = arcpy.mapping.ListLayers(mxd, "Rivers", df)[0] in_symbology_layer = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr") arcpy.ApplySymbologyFromLayer_management(in_layer,in_symbology_layer)
Article ID: 000012251
Get help from ArcGIS experts
Download the Esri Support App