I'm having issues when trying to symbolize a layer from a .lyr template using a python script. The templates work when imported in ArcMap as seen below:
But when run with the following Python code:
df = arcpy.mapping.ListDataFrames(mxd, "dfImage" + str(dfNum))[0] legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "dfImage" + str(dfNum) +"_legend")[0] fc1 = arcpy.mapping.Layer(fcGrid) arcpy.mapping.UpdateLayer(df, fc1, arcpy.mapping.Layer(symbologyTemplatePath + "VI_data.lyr")) arcpy.ApplySymbologyFromLayer_management(fc1, arcpy.mapping.Layer(symbologyTemplatePath + "VI_data.lyr")) fc1.symbology.valueField = gridCol legend.autoAdd = True arcpy.mapping.AddLayer(df, fc1, "BOTTOM") arcpy.RefreshActiveView() for lyr in legend.listLegendItemLayers(): legend.updateItem(lyr, styleItem) legend.elementHeight = 1.0 It changes the colors, and the legend labels aren't truncated to 2 decimal places:
Does anyone know how to fix this? Much thanks!
أكثر...


But when run with the following Python code:
df = arcpy.mapping.ListDataFrames(mxd, "dfImage" + str(dfNum))[0] legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "dfImage" + str(dfNum) +"_legend")[0] fc1 = arcpy.mapping.Layer(fcGrid) arcpy.mapping.UpdateLayer(df, fc1, arcpy.mapping.Layer(symbologyTemplatePath + "VI_data.lyr")) arcpy.ApplySymbologyFromLayer_management(fc1, arcpy.mapping.Layer(symbologyTemplatePath + "VI_data.lyr")) fc1.symbology.valueField = gridCol legend.autoAdd = True arcpy.mapping.AddLayer(df, fc1, "BOTTOM") arcpy.RefreshActiveView() for lyr in legend.listLegendItemLayers(): legend.updateItem(lyr, styleItem) legend.elementHeight = 1.0 It changes the colors, and the legend labels aren't truncated to 2 decimal places:

Does anyone know how to fix this? Much thanks!
أكثر...