Select to view content in your preferred language

How to add item to exist legend using arcpy?

3325
2
07-02-2015 06:24 AM
Yaron_YosefCohen
Occasional Contributor II

Hi,

Can i add an item (layer "polygon") in the TOC  to exist legend in arcmap using python?

I have a several mxd's with those layers:

1.jpg2.jpg

I tried search in ArcGIS Help 10.1 but didn't find a way to do it.

Tags (3)
0 Kudos
2 Replies
IanMurray
Frequent Contributor

Hi YYC,

Arcpy Mapping does not allow for individual layers to be manually added to a legend.  However, you can set a legend to auto-add new layers added the map with add layer or addlayertoGroup to the legend.  If you set this property to true before you add the layer you want, it should add it to your legend.  If it already exists in the map, either moving it to a group layer or remove and adding it again should add it to the legend.

ArcGIS Help 10.1

XanderBakker
Esri Esteemed Contributor

If you have a specific symbology defined for the polygon layer, you might want to save the layer as a layerfile (.lyr) before removing it (see saveACopy (file_name, {version}) method of Layer—Help | ArcGIS for Desktop )

In this help topic (10.3) LegendElement—Help | ArcGIS for Desktop sample code is provided that shows the use of the autoAdd property of the legend by python code.

0 Kudos