I'm trying to write a script to update a TextElement object in a batch of MXDs. (I know there's a similar discussion going on right now but I didn't see anything relevant to my issue.) So far I've been getting the error:
This is my code:
I've checked every step of the routine up until the text is set and everything looks fine (no unexpected nulls). Can anyone see anything wrong with what I'm doing here?
Thanks!
Code:
RuntimeError: TextElementObject: Error in setting textCode:
import os
import arcpy
# Loop over MXDs
root = r'H:\myDir'
for file in os.listdir(root):
print 'Working on ' + file
path = os.path.join(root, file)
mxd = arcpy.mapping.MapDocument(path)
text_elms = arcpy.mapping.ListLayoutElements(mxd, 'TEXT_ELEMENT')
the_text_elm = None
# Loop over text elements to find subtitle
for text_elm in text_elms:
i = text_elm.text.find('Archit')
if i > -1:
the_text_elm = text_elm
break
# Update
if the_text_elm:
i = the_text_elm.text.find('Archit')
new_text = the_text_elm.text[:i] + 'Historic Resources'
the_text_elm.text = new_text
mxd.save()
else:
print 'Did not update'Thanks!