Select to view content in your preferred language

Automatically add layers to legend

2236
3
03-17-2017 10:16 AM
RobMcCulley
Occasional Contributor

I've got a ArcGIS Pro project file with a single map, and 28 layouts that reference the map.  All 28 layouts have a legend that also references the map.  I've created a python script that uses arcpy.mp to add layers to the map, and export all 28 layouts to pdf's.  Unfortunately, when the layers get added to the map, they are not added to the legends. I've also tried manually adding the layers to the map within ArcGIS Pro, and the layers are not added to the legends.

I've checked the Format Legend pane, and all of the Synchronize with map options are checked.

I'm looking for one of two solutions:

  1. Have the layers automatically added to all of the legends when I add them to the map
  2. Add the layers programatically to the legend using arcpy.mp before I export the layout to pdf.

Is there a way to add the layers to the legend using arcpy?  From browsing the documentation, the only way I've found to add layers to an existing legend is to drag and drop them from the Contents pane to the Legend item.  How do I replicate this in arcpy?

I'm using ArcGIS Pro version 1.4.1 on a project file that was created in ArcGIS Pro 1.4.1.

0 Kudos
3 Replies
RobMcCulley
Occasional Contributor

I've explored this issue a bit more - it seems to be a bug?

If I create a new layout, add my map to the layout, and add a new legend to the layout, all layers get added to the legend as expected.  In the format legend pane, I've got all of the "Synchronize with map" options selected.

At this point, any new layers added to the map are also added to the legend, as expected.

Now, there a few layers I don't want in the legend, so I can either uncheck, or remove them from the legend, and this works as expected.

However, once I've removed items from the legend, either by unchecking them, or right clicking and selecting remove, new layers added to the map are no longer added to the legend regardless of the "Synchronize with map" options.  As soon as one or more layers are removed from the legend, the only way I can get newly added layers into the legend is to drag the layers from the Map Frame table of contents into the legend.

There doesn't appear to be any way to control legend items from arcpy.mp.

0 Kudos
CassKalinski
Regular Contributor

Still seems to be an issue with v2.2.4. Adding layers to the map does not automatically update the legend, even when the synchronize settings are in place. 

0 Kudos
RobMcCulley
Occasional Contributor

I've been informed by ESRI that it will be fixed with the 2.3 release.