0

I'd like to use specific colors for my Unique Values. I tried creating another layer. choosing the colors that I want, and using the ApplySymbologyFromLayer. I also updated my new layer to make sure it was classified as Unique Values. When I refresh my map, no colors are showing up, and the wrong Value Field is appearing when I manually look at symbology. Has anyone else had this problem? I get no error messages, and when I print the valueField and the symbologyType, the correct fields appear.

Here is my code -

color_layer=arcpy.mapping.ListLayers(mxd)[-6]
lyr=arcpy.mapping.ListLayers(mxd)[-1]
arcpy.mapping.UpdateLayer(df,lyr,color_layer,True)
lyr.symbology.valueField="color"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
arcpy.ApplySymbologyFromLayer_management(lyr, color_layer)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
  • Hi Katherine, I added a little formatting to your code, just by putting 4 spaces in front of each line... it's easier to read that way. – mr.adam Apr 13 '15 at 15:12
1

I've tested your script with a bit of modification:

mxd = arcpy.mapping.MapDocument("CURRENT")
layers=arcpy.mapping.ListLayers(mxd)
color_layer=layers[-1]
lyr=layers[-2]
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.mapping.UpdateLayer(df,lyr,color_layer,True)
lyr.symbology.valueField="color"
lyr.symbology.addAllValues()
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
arcpy.ApplySymbologyFromLayer_management(lyr, color_layer)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()

it works as expected. I think your issue is something to do with picking appropriate layer and/or field naming match in both layers

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.