Use Arcpy in ArcGIS Pro to replace text in layout fails

814
0
03-14-2019 11:26 AM
SaraTaylor2
New Contributor

I have a python code that takes an existing aprx file and attempts to find and replace text in the layout. When the code runs, one element updates seamlessly and the other does not. The failing element lists the appropriate text in the python when the elements are listed, but the actual text display in the map layout does not change. I have tried several different methods for getting python to list and call this text specifically, but nothing seems to work. A subset of the full code with the working and failing elements in listed below.

Here is the full text of the element I am trying to replace a portion of. This is in a text box in the layout.

Potentiometric Surface at
Shallow Wells 12/06/2018

import arcpy,os

arcpy.env.overwriteOutput = 1

aprx = {HIDDEN for privacy}
F3_PDF = r'{HIDDEN for privacy}\F3 Layout_Test_3-13-19.pdf'

##This is the failing element##

for lyt in aprx.listLayouts("F3 Layout"):
    for elm in lyt.listElements("TEXT_ELEMENT"):
        if elm.text == "12/06/2018":
            elm.text = "03/05/2019"
del lyt

##This is the passing element##

for lyt in aprx.listLayouts("F3 Layout"):
    for elm in lyt.listElements("TEXT_ELEMENT"):
        if elm.text == "Map Created: January 2019":
            elm.text = "Map Created: March 2019"
lyt.exportToPDF(F3_PDF, resolution = 300)
aprx.save()
print("F3 Export Complete")
del lyt

Here are a few of the if statements I have tried to use to replace the appropriate text, each time I have tried to use these ifs to find the text, it fails and does not print the text element I am looking for.

        if elm.text == "12/06/2018":

        if elm.text == "Shallow Wells 12/06/2018":

        if elm.text == "Potentiometric Surface at Shallow Wells 12/06/2018":

        if elm.text == "Potentiometric Surface at'/n'Shallow Wells 12/06/2018":

        if elm.text == "Potentiometric Surface at'/r'Shallow Wells 12/06/2018":

        if elm.text == "Potentiometric Surface at" + '/r' + "Shallow Wells 12/06/2018": 

        if elm.text == "Potentiometric Surface at" + '/n' + "Shallow Wells 12/06/2018":

Any help is appreciated. Thank you!

0 Kudos
0 Replies