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:
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.
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.