Updating Symbology on Layer using ArcPy?

427
0
07-30-2019 07:21 AM
deleted-user-Bzr4vpYlGUla
New Contributor

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:

import arcpy
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    
mxd.save()
Symbology()

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 code.

Tags (2)
0 Kudos
0 Replies