1

I'm struggling with an issue which I think is a bug in arcpy. I am using AddSymbologyFromLayer_management to apply the symbology from a reference layerfile (yes, an actual layerFILE, not a layer within the .mxd) to a newly created polygon shapefile which is displayed as a layer.

This works fine, even when I change what the field the symbology shall be based on. However, when I also change the class breaks (I use GRADUATED_COLORS here), the outlines, which are set to "No color" in the reference layerfile, are set back to default, which means some kind of grey with 0.4pt width.

This behaviour only occurs when I change the class breaks via code, if I keep them as they are, everything is fine.

This is what I basically do within the code:

# get reference layer
ref_lyr_file = os.path.join(workspace, 'styles', 'graduated_colors_reference_style.lyr')
# get newly created layer
new_lyr = arcpy.mapping.ListLayers(mxd, lyr, mapDF)[0]
# import symbology from reference layer-file
arcpy.ApplySymbologyFromLayer_management(new_lyr, ref_lyr_file)
# set value field
new_lyr.symbology.valueField = draw_param_dict[draw_parameter]
# reclassify values
new_lyr.symbology.reclassify()
breaks = new_lyr.symbology.classBreakValues
# round values nicely as new class breaks
lenMin = len(str(int(breaks[1])))
new_breaks = [int((round(b / (10 ** lenMin), 2)) * (10 ** lenMin)) for b in breaks]
# update map document
new_lyr.symbology.classBreakValues = new_breaks
arcpy.RefreshTOC()
arcpy.RefreshActiveView()

How I create the new breaks is not important, so you can skip this section. The thing is: the polygon outlines are set back to the default color ONLY AFTER applying new class break values.

Does anyone know how to get around this?

2
  • Can you make a reference layer with the symbology you'll want after the break and apply it then or will the breaks be different every time?
    – J Kelly
    Oct 20, 2016 at 12:18
  • Sorry for not responding for a week, I've been out of office... The breaks change every time, so unfortunately, there's no chance here.
    – s6hebern
    Oct 28, 2016 at 6:31

1 Answer 1

1

I've been communicating back and forth with ESRI and they finally came up with an answer: it seems to be a bug in the arcpy API, which shall be fixed with ArcGIS 10.5 (pre-release already available). As soon as I can confirm this, I will post it here. From what ESRI told me, there is no workaround for versions lower than 10.5 except for manual adjustment.


ESRI was right, the bug is fixed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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