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) # 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))) 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?