1

I have a vector layer that I add to a data frame. I modify the unique values symbology class labels. I then export the map document as a PDF and the labels in the PDF do not reflect the modifications.

Here is the code and the resulting print statements:

#Dissolve zones and get a list of acres
arcpy.Dissolve_management(pathScratchGDB + "fcZones_Proj", pathScratchGDB + "fcSurface_Temp",
    dissolve_field="ph1", statistics_fields="acres SUM", multi_part="MULTI_PART", unsplit_lines="DISSOLVE_LINES")
lsAcres_Temp = list(row.getValue("SUM_acres") for row in arcpy.SearchCursor(pathScratchGDB + "fcSurface_Temp", fields="SUM_acres"))

#Format symbology
df = arcpy.mapping.ListDataFrames(mxdSurface, "df1")[0]
df.spatialReference = srCover
legend = arcpy.mapping.ListLayoutElements(mxdSurface, "LEGEND_ELEMENT", "df1_legend")[0]
legend.autoAdd = True
lyrTemp = arcpy.mapping.Layer(pathScratchGDB + "fcZones_Proj")
arcpy.ApplySymbologyFromLayer_management(lyrTemp, pathLayerTemplates + "/zone_surface.lyr")
lyrTemp.symbology.valueField = "ph1"
lyrTemp.symbology.addAllValues()

#Label zones
lblClass = lyrTemp.labelClasses[0]
lblClass.expression = "\"<FNT size = '8'>\" + " + "[zone_num]" + " + \"</FNT>\""
lyrTemp.showLabels = True
lblClass.showClassLabels = True

#Add Layer
arcpy.mapping.AddLayer(df, lyrTemp, "TOP")
#Update legend style
for lyr in legend.listLegendItemLayers():
    legend.updateItem(lyr, styleItem)

#Modify legend to include acres
print(lyrTemp.symbology.classLabels) #[u'7.1', u'7.2', u'7.4']
temp = lyrTemp.symbology.classLabels
iNumLabels = len(temp)
for i in range(0,iNumLabels):
    temp3 = str(temp[i]) + " (" + str(round(lsAcres_Temp[i],1)) + " ac)"
    temp[i] = str(temp3)
lyrTemp.symbology.classLabels = temp
print(temp) #['7.1 (33.0 ac)', '7.2 (43.4 ac)', '7.4 (69.4 ac)']
print(lyrTemp.symbology.classLabels) #[u'7.1 (33.0 ac)', u'7.2 (43.4 ac)', u'7.4 (69.4 ac)']
arcpy.RefreshActiveView()

#Export PDF
arcpy.mapping.ExportToPDF(mxdSurface, "../Scratch/temp.pdf")

And here is an image snipped from the PDF:

Legend without modifications

Why don't the modified class labels follow through to the PDF?

It might be worth noting that I've successfully exported a PDF with the modifications when I do everything in the ArcMap python window.

closed as off-topic by PolyGeo Mar 22 '16 at 21:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Where is your code for exporting the map to a pdf? – Tom Mar 17 '16 at 22:36
  • 3
    You do need to show more complete code. Where is the list lsAcres_Temp coming from? That is key. Also, since your range starts at 0, the last number should be len - 1. Also, if you look at the help file example, I think you are missing a couple steps. – RHB Mar 17 '16 at 23:04
  • You do not seem to have shown us where your MapDocument object (mxdSurface) is created. When you present code snippets here they should work up to where you are stuck. In this one I suspect that there is quite a bit of code that could be omitted to create a simpler code snippet that still illustrates where you are stuck. I recommend to keep editing it down until it starts to behave as expected, and then put back the last line to see if that can be isolated as what causes your issue. – PolyGeo Mar 22 '16 at 21:56

Browse other questions tagged or ask your own question.