I have a python addin button that creates a layer file from a polygon feature class in ArcMap. I want to take that layer file and, with user input from a combobox, apply it back to the feature class using a different value field. For example, I have a feature class called "names" with the following attributes:


And I want to create a layer file based on the unique values for Name and then use that layer file to display Name_Change1 and Name_Change2 so that my colors remain consistent for each unique value (ex: Finnley is always purple, Dylan is always green). This is possible in ArcMap by importing the symbology from the layer file and changing the value field. However, I need this functionality in a python toolbar.

Right now, I am creating separate layers for each field and using those. This works but it requires a lot of set-up in order to use the addin:

if combobox_value == "Name_Change1":
    if arcpy.Exists("Name_Change1.lyr"):
        arcpy.ApplySymbologyFromLayer_management(names, "Name_Change1.lyr")

But I want it to be something like:

if combobox_value == "Name_Change1"
    if arcpy.Exists("Name.lyr"):
        #assign/change value field of Name.lyr
        arcpy.ApplySymbologyFromLayer_management(names, "Name.lyr")

Where symbology is always pulled from "Name.lyr".

I guess I really wish that the ApplySymbologyFromLayer tool had a parameter for the value field, but that doesn't seem to be the case. And I haven't found another tool/method that will allow this. Does anyone have any ideas?


Sounds like you're looking for the valueField property in the UniqueValuesSymbology class: http://resources.arcgis.com/en/help/main/10.1/index.html#/UniqueValuesSymbology/00s30000005s000000/

  • I tried that, but every time I changed the value field the symbology would refresh and my colors would not stay consistent. – GiraffesInSocks Aug 21 '14 at 22:02
  • Ah, I see the problem. I think your solution (import the symbology from the layer file in ArcMap, change the value field, and then create separate layer files for each value field required) may be the best option, due to the lack of a value field parameter for ApplySymbologyFromLayer. – XIY Aug 22 '14 at 2:45
  • There also appears to be an option in ArcObjects. – XIY Aug 22 '14 at 3:04

Your Answer

