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?

4

Try replacing both the newline and 'aaa':

.replace('\naaa', "\nTEXT_ELEMENT")

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.