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?