5

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:

attribute_table

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?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 20, 2014 at 19:09

1 Answer 1

3

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/

answered Aug 20, 2014 at 23:09
3
  • I tried that, but every time I changed the value field the symbology would refresh and my colors would not stay consistent. Commented Aug 21, 2014 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. Commented Aug 22, 2014 at 2:45
  • There also appears to be an option in ArcObjects. Commented Aug 22, 2014 at 3:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.