AnsweredAssumed Answered

Replace TextElement

Question asked by jpilbeam Champion on Jul 29, 2020
Latest reply on Aug 5, 2020 by jpilbeam

I have a text element that I can't seem to find. I'm using this support document: TextElement—ArcGIS Pro | Documentation  I can find it if I use the the text Name (Text 37), but in my case I have a multitude of maps and Text 37 might have irrelevant text in another map. So, in short I need to find and replace the Text.


Here's the script I'm using but it doesn't change the Text. I think maybe it's because "Lawrence M. Walsh Will County Executive" is in two lines. Can anyone see what the issue may be?

import arcpy, os

#workspace folder
arcpy.env.workspace = ws = r"pathto\TestFolder"
#print the number of aprx files in the workspace folder
aprxlist = arcpy.ListFiles("*.aprx")
print("Currently {0} maps to be updated.".format(len(aprxlist)))

#list the aprxs of the workspace folder
for aprxname in arcpy.ListFiles("*.aprx"):
    print("changing text: {}\t".format(aprxname))
    aprx = + "\\" + aprxname)

#replace title date that occurs in the document
    for lyt in aprx.listLayouts():
        for elm in lyt.listElements('TEXT_ELEMENT'):
            if elm.text == 'Lawrence M. Walsh': #text
                elm.text = 'Denise Winfrey' #new text
    #do not include this delete statement inside the above loop or it will
    #delete the mxd object inside the loop. Make sure to dedent.
    del aprx