My goal is to generate any number of MXD files with custom class-break-values using a consistent, pre-defined style.
For example, in ArcMap (10.2.2 and 10.3.1), I have an MXD with a graduated-color layer that has a single class-break-value symbol in it. I want to update this layer's symbology from ArcPy using a .lyr file without affecting that class-break-value.
I can do this very easily from ArcMap:
TOC > Layer Properties > Symbology > Import > Select the .lyr file > "Just the symbols" option > OK
Is there a way to mimick this from ArcPy?
When I try the following code (using the same .lyr file as above), the TOC layer's style is updated correctly, but its class-break-value is overwritten by the class-break-value from the .lyr file:
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") dataFrame = arcpy.mapping.ListDataFrames(mxd) sourceLayer = arcpy.mapping.Layer(pathToLyrFile) destLayer = arcpy.mapping.ListLayers(mxd, existingLayerName) arcpy.ApplySymbologyFromLayer_management(destLayer, sourceLayer) arcpy.RefreshTOC()
UpdateLayer has a symbol-only option, but it also overwrites the class-break-value:
arcpy.mapping.UpdateLayer(dataFrame, destLayer, sourceLayer, True)
Originally, I tried importing the .lyr file into a blank MXD file after modifying the class-break-value, but when I change the value this way, the class-break's symbol is lost (and we are back to where we started):
import arcpy mxd = arcpy.mapping.MapDocument(mxdPath) dataFrame = arcpy.mapping.ListDataFrames(mxd) layer = arcpy.mapping.Layer(pathToLyrFile) layer.symbology.classBreakValues = [0, 50] arcpy.mapping.AddLayer(dataFrame, layer, 'TOP') mxd.save()