Arcpy, aprx, layouts and maps... yeah! ArcGIS Pro - oh no!

Discussion created by agelfert on Mar 4, 2020
Latest reply on Mar 4, 2020 by Dan_Patterson

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!