4

I have an template mxd I reference with several pre-defined layers. The only variable I need to modify is the color of certain symbols in the layer. I have tried to modify and dig around the Symbology Object but I cannot access the colors of each Unique Value Symbol.

This is how I am accessing the the Symbology of the individual layers. There doesn't seem to be and option to change the color a value.

  • I am using ArcGIS 10.2.1

    mxd_file = r"some\path\file.mxd"
    mxd = arcpy.mapping.MapDocument(mxd_file)
    
    # getting data frame   
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    
    # getting street layer
    street_layer = arcpy.mapping.ListLayers(mxd, 'Street', df)[0]
    
    if street_layer.symbologyType == 'UNIQUE_VALUES':
        # trying to access all possible properties of the symbology object
        street_symbology = street_layer.symbology
        desc = street_symbology.classDescription
        labels = street_symbology.classLabels
        values = street_symbology.classValues
        show_other_values = street_symbology.showOtherValues
        value_field = street_symbology.valueField
    del mxd, df
    
    layer_file = r"some\path\file.lyr"
    arcpy.SaveToLayerFile_management(path_layer, layer_file)
    
1

Example of using Apply Symbology From Layer tool with Python. Start by defining symbology for the first layer in map and then use this to set symbology of all other layers:

import arcpy
mxd=arcpy.mapping.MapDocument("CURRENT")
lyrlist=[f.name for f in arcpy.mapping.ListLayers(mxd)]
lyrlist=lyrlist[1:] #exclude the first layer
for lyr in lyrlist:
    arcpy.ApplySymbologyFromLayer_management(lyr,"templateSymbologyLayer") 
1

I agree with the comment by @Hornbydd:

The short answer is no. The only way I am aware using the standard geo-processing tools is to use the Apply Symbology From Layer tool. It may be possible to access the Symbology using python to drive ArcObjects, you would have to do some research on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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