2

I work with several maps with this text:

enter image description here

enter image description here

and i try to change the second line only into "landUse" by using this code:

import arcpy
from arcpy import env
env.workspace = r"G:\desktop\Project"
for num, mxdname in enumerate((arcpy.ListFiles("*.mxd")),start = 1):
 print '\n',num,mxdname
 mxd = arcpy.mapping.MapDocument(
 r"G:\desktop\Project\\" + mxdname)
 for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
 elm.text = elm.text.replace(u'aaa'[1], u'landUse')
 mxd.save()
del mxd

when i run it i get this unwanted result:

enter image description here

whereas i want this result:

enter image description here

i didn't find an answer in Changing part of text element using ArcPy?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 12, 2019 at 7:57
0

1 Answer 1

4

Try replacing both the newline and 'aaa':

.replace('\naaa', "\nTEXT_ELEMENT")
answered May 12, 2019 at 8:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.