3

I am trying to replace a single, 3 line text elements in ArcGIS Pro 2.8.3, with a new, single 3 line text elements. The existing text looks like this in the layout:

NATIONWIDE PERMIT 3  
COD ART RANK PARK TO DEMON BRIDGE  
LA PLATA  COUNTY, COLORADO

and the text I want is

NATIONWIDE PERMIT 3  
ANIMAS RIVER TRAIL - RANK PARK SEGMENT   
LA PLATA  COUNTY, COLORADO

My code does not throw any errors, but it does not change the desired text. I believe it is related to the multiple lines, since the same code works fine for single line text elements. I don't think it is finding the existing text. My code is:

aprx = arcpy.mp.ArcGISProject(r"CURRENT")
for lyt in aprx.listLayouts():
    for elm in lyt.listElements("TEXT_ELEMENT"):
        if elm.text == "NATIONWIDE PERMIT 3 \n COD ART RANK PARK TO DEMON BRIDGE \n LA PLATA COUNTY, COLORADO":
            elm.text = "NATIONWIDE PERMIT 3 \n ANIMAS RIVER TRAIL - RANK PARK SEGMENT \n LA PLATA COUNTY, COLORADO"
aprx.save()
del aprx

I have also tried

import arcpy
aprx = arcpy.mp.ArcGISProject(r"CURRENT")  
for lyt in aprx.listLayouts(): 
    for elm in lyt.listElements("TEXT_ELEMENT"):  
        if elm.text == """NATIONWIDE PERMIT 3
            COD ART RANK PARK TO DEMON BRIDGE
            LA PLATA COUNTY, COLORADO""":
              elm.text = """NATIONWIDE PERMIT 3
                ANIMAS RIVER TRAIL - RANK PARK SEGMENT
                LA PLATA COUNTY, COLORADO"""
aprx.save()
del aprx

1 Answer 1

4

Your first sample of code worked for me. I suspect its because you are putting spaces before and after the newline (\n) character when there is none in your original text element.

1
  • Thank you for your insight. I realized that it wasn't finding the text because there was a new line before the first line of text. Once I added a "\n" before the first line of text, and removed the spaces, it worked. Thanks.
    – sparky
    Jan 20 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.