I've been trying to update the symbology of a layer on my Python script. The layer that is to be updated shows the percentage of an age range in each region across a county. I have created a test layer (as suggested on GraduatedColorsSymbology ArcPy Website) which copies the symbology of the test layer to the layer I am editing. I have set the symbology of this test layer to use the same dataset as the new layer, but uses a different age range (0 - 16 years).

This worked as expected, so now I want to update the Symbology to use a different age range (65 and Over) using the GraduatedColorsSymbology ArcPy page.

Below is my code:

def Symbology():
    mxd = arcpy.mapping.MapDocument(r"C:\MyMaps\Ages.mxd")
    df = arcpy.mapping.ListDataFrames(mxd)[0]

    updateLayer = arcpy.mapping.ListLayers(mxd, "Age_Range")[0]
    sourceLayer = arcpy.mapping.Layer(r"C:\MyLayers\TEST_LAYER.lyr")

    arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)

    if updateLayer.symbologyType == "GRADUATED_COLORS":
        updateLayer.symbology.valueField = "PCT_65_OVR"
        updateLayer.symbology.numClasses = 5



When I execute this code, I get the error ValueError: PCT_65_OVR. I made sure that the attribute name in the code is the same as what is on the symbology layer, so not sure why I am getting this error.

  • Do you have a join on that layer? – Hornbydd Jul 30 at 20:01
  • @Hornbydd yes I have a function that does the map automation. That has the join code. Without the def shown above, I can see on ArcMap that the attributes have been joined – Rehaan Aatif Jul 31 at 8:23

Your Answer

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

Browse other questions tagged or ask your own question.