Select to view content in your preferred language

Dynamic Layout Title (ArcGIS Pro)

4650
11
Jump to solution
12-18-2017 01:04 PM
Business_IntelligenceSoftware
Regular Contributor

Is there a way to make the title of a layout dynamic with a feature class? I know there is dynamic text with the Map Frame, Project Name, Metadata, and many other things. From the research I have done it seems like it might have been possible in ArcMap, but I have been unable to find anything in ArcGIS Pro that would allow for the layout title to be dynamic with a feature class. 

To expand a little further. I have a large arcpy script where 80 layouts are created (from 1 template layout) and exported into a PDF, but right now each layout has the same generic title so sometime 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.

I considered using the following code, which uses the TextElement, but it looks to me like I would have to specify each individual title for every layout. And if I have 80+ layouts, that could take a long time. 

p = arcpy.mp.ArcGISProject("Current")
for lyt in p.listLayouts():    
    for elm in lyt.listElements("TEXT_ELEMENT"):        
        if elm.name == "title": # this is the element name set via text properties                 
            # add layout feature class check logic            
            elm.text = "New Title" # changing title name

Am I reading this right?

Is there a better way?

11 Replies
Business_IntelligenceSoftware
Regular Contributor

The final code I used to get the results I was looking for is:

import arcpy
from arcpy import env
import sys
import os
import datetime
elm_name = "My Dynamic Title" # the name you assign to the title (TEXT) element
p = arcpy.mp.ArcGISProject(r"C:\arcGIS_Shared\Python\CenterHeatMaps.aprx")
for lyt in p.listLayouts("Layout_King"): # get the element
    for elm in lyt.listElements("TEXT_ELEMENT"):
        if elm.name == elm_name:
            text_elm = elm
            break

for m in p.listMaps(): # loop through your layer / layouts / maps
    for lyr in m.listLayers("BCBS*"):
        new_title=lyr.name # do your logic with the layer
        elm.text=new_title
        lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\BCBS_" + elm.name[13:] + ".pdf") # export the map
        print(elm.name[13:])

Thank you everyone for your help and input!

DanPatterson_Retired
MVP Emeritus

so the slice was the problem then