AnsweredAssumed Answered

Change text using arcpy

Question asked by yaron148 on Aug 11, 2015
Latest reply on Aug 13, 2015 by yaron148

Hi  there,

i try to change oldText with myString in 25 mxd's ( in the layout ).

The text (i used draw tool to create it) contain 2 row:

land use


myString is the new text

i try this code but python only print list of mxd names in the folder:


import arcpy
from arcpy import env 

env.workspace = r"D:\PROJECTS\ab\gis"
counter = 0
for mxdname in arcpy.ListFiles("*.mxd"):
    print mxdname
    oldText = 'land use'
    oldText = oldText + '\n'
    oldText = oldText + 'fuel'
    mxd = arcpy.mapping.MapDocument(r"D:\PROJECTS\ab\gis\\" + mxdname)
    myString = 'free fuel'
    myString = myString + '\n' 
    myString = myString + 'gas'
    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if elm.text == oldText :
            elm.text = myString
    counter = counter + 1
del mxd

is it possible with python 2.7.8?

thanks in advance.