Love the fact that you can interact with APRX projects so well in Python using arcpy. Iterating through maps and layout, layers, or layout elements. But while trying to automate map making, I kept banging my head against the well because despite things like:
# loop through layout.listElements
if elem.type == 'LEGEND_ELEMENT':
legend = elem:
# ...
legend.syncLayerVisibility = True
legend.syncLayerOrder = True
# ...
layout.exportToPDF(PDF_File, resolution = 300)
my legend wouldn't show up in the PDF I'm generating. Then I noticed that I could see it containing only one layer inside of ArcGIS Pro where my layout is set up instead of showing ALL layers. After trying everything imaginable (and more) in my code and getting blisters on my finger tips navigating the ridiculous panes of pain in Pro, I realized that the current width of my legend element was too much for the page width. But it didn't just cut off the text labels of some of the items - it hid them completely and therefore rendered a blank legend in the app, which leads to a blank legend in the PDF. Oh, come on!
Good catch.
Are you suggesting that it would be useful to check the size of the legend element and compare it to the page size?
LegendElement—ArcPy | Documentation
elementWidth (Read and Write) | The width of the element in page units. |
MapFrame—ArcPy | Documentation
same as for MapFrame
elementWidth (Read and Write) | The width of the map frame on the page layout. The units assigned or reported are in page units. |
Maybe these checks aren't automatic.