4

In ArcMap Style Manager, I have a Preset Color Ramp defined. I would like to control how the colors are applied when doing Add All Values, but it seems colors in the set are applied at random and differently in ArcMap and with arcpy.mapping.

When I apply the ramp from ArcMap, Layer Properties, Symbology, Add All Values, these are the results:

ArcMap Layer Properties Symbology Add All Values

When I apply the ramp using arcpy.mapping and lyr.symbology.addAllValues(), these are the results:

enter image description here

It is a totally different set of colors, the orange from the first image and brown from the second are different. I have a Python automated map export process and I would like some consistency in how colors are applied for this layer.

Does anyone have a way to make this more consistent?

Here is the code snippet:

templateMxd = r'D:\...\biodiv_npc_map.mxd'
mxd = arcpy.mapping.MapDocument(templateMxd)
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    lyrList = arcpy.mapping.ListLayers(mxd, "*", df)
    for lyr in lyrList:
        if lyr.name == "Mapped Native Plant Communities near or on property":
            lyr.symbology.addAllValues()
  • I still cannot see how do you apply a particular ramp using arcpy code. Don't you need to update the symbology using .lyr file for which a color ramp is defined? – Alex Tereshenkov Feb 17 '17 at 7:41
  • You can also run addAllValues() on a layer that is already part of an existing MXD, which is what my script does. The properties for the layer are as defined in the screen cap of the Layer Properties window above and are saved in biodiv_npc_map.mxd. – jeffreinhart Feb 18 '17 at 16:57
  • 1
    You can create a source layer and use it as a template. support.esri.com/en/technical-article/000012251 – BBG_GIS Nov 23 '17 at 0:02
1

you need to create a .lyr file that uses the desired symbology schema (colors, sizes etc.)

then use the following arcpy code to use this schema on the desired layer in the mxd.

lyr1 = "layer_1"
symbolLyr1 = r"path\to\the\.lyr\file"
arcpy.ApplySymbologyFromLayer_management(lyr1, symbolLyr1)

HERE is the documentation for this arcpy function

  • I don 't think that addresses the issue. I am not setting colors for every category, which would be required to do a layer file. I just want the color ramp to be applied consistently. – jeffreinhart Dec 13 '17 at 17:16

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.