I have a large ArcPy script where 80 layouts (created from 1 template layout - "Layout_King") are created and exported into a PDF, but right now each layout has the same generic title so sometimes it is hard to know what data is being shown in the layout. This problem could be solved if the layout's title was Dynamic with the feature class that is being portrayed in the layout.
The following script is my first pass at achieving a layout title that would be "Dynamic" with a feature class' name:
import arcpy
from arcpy import env
import sys
import os
elm_name = "My Dynamic Title"
p = arcpy.mp.ArcGISProject(r"C:\arcGIS_Shared\Python\CenterHeatMaps.aprx")
for lyt in p.listLayouts("Layout_King") [0]:
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.name==elm_name:
text_elm=elm
break
for m in p.listMaps():
for lyr in m.listLayers("BCBS*"):
new_title=lyr.name
elm.text=new_title
lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\BCBS" + elm.name[13:] +
".pdf")
print(elm.name[13:])
However, when I tested the code I got the following error:
Traceback (most recent call last):
File "<string>", line 8, in <module>
TypeError: 'Layout' object is not iterable
What I'm doing wrong? Also, does it look like I'm at least on the right track with the code?