Select to view content in your preferred language

Edit legend label or description with python

6459
3
Jump to solution
03-19-2013 10:30 AM
JasonTaylor
Deactivated User
Hi,

In a nut shell, If anyone knows how to change the text in legend labels in arcpy let me know.

This is what I have tried so far...

I am trying to edit the description of the layer using the layer.description method and then setting the legend item's style to one that uses the description as the primary legend label.

I can set the style property and when I print the layer's description to the terminal it appears to be set, however when I open the mxd, the description isn't filled out (under the symbology tab of the layer's properties).

Here's a sample of my code

for item in mxdlist:     if ".mxd" in item:         figpath = path + item         mxd = arcpy.mapping.MapDocument(figpath)         for item in arcpy.mapping.ListLayers(mxd):             if "RIPRAP" in item.name:                 item.description = 'Rip Rap'                 print "....Updated"                 print item.description         legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]         legendlayers = legend.listLegendItemLayers()         for item in legendlayers:             if "RIPRAP" in item.name:                 style = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items","blobDesc")[0]                 legend.updateItem(item, style)                 print item.name     mxd.save()     del mxd


I think that the layer property for description isn't what I think it is, but maybe somebody else knows what I am missing.

Thanks in advance!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
The layer.description property is the layer's metadata description you would find if you right-clicked on a layer in the TOC, clicked properties and looked at the General tab.

At 10.1 a subset of symbology types were exposed: GraduatedColors, GraduatedSymbols, RasterClassified and UniqueValue:

http://resources.arcgis.com/en/help/main/10.1/#/GraduatedColorsSymbology/00s30000005z000000/
http://resources.arcgis.com/en/help/main/10.1/#/GraduatedSymbolsSymbology/00s30000005q000000/
http://resources.arcgis.com/en/help/main/10.1/#/RasterClassifiedSymbology/00s30000005p000000/
http://resources.arcgis.com/en/help/main/10.1/#/UniqueValuesSymbology/00s30000005s000000/

If you are using one of these renderers, you can change the labels and/or descriptions.

Jeff

View solution in original post

0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor
The layer.description property is the layer's metadata description you would find if you right-clicked on a layer in the TOC, clicked properties and looked at the General tab.

At 10.1 a subset of symbology types were exposed: GraduatedColors, GraduatedSymbols, RasterClassified and UniqueValue:

http://resources.arcgis.com/en/help/main/10.1/#/GraduatedColorsSymbology/00s30000005z000000/
http://resources.arcgis.com/en/help/main/10.1/#/GraduatedSymbolsSymbology/00s30000005q000000/
http://resources.arcgis.com/en/help/main/10.1/#/RasterClassifiedSymbology/00s30000005p000000/
http://resources.arcgis.com/en/help/main/10.1/#/UniqueValuesSymbology/00s30000005s000000/

If you are using one of these renderers, you can change the labels and/or descriptions.

Jeff
0 Kudos
JasonTaylor
Deactivated User
Awesome, thanks for the tip. I hadn't thought to look for label editing in those functions because my feature uses the single symbol renderer.

Thanks again!
0 Kudos
JeffBarrette
Esri Regular Contributor
It would be a work around but you could add a field to your table, calculate all values to be the same and then use the unique value renderer to symbolize the single symbol.

Jeff
0 Kudos