rmartin4

TexElementObject: Error in setting text

Discussion created by rmartin4 on Aug 19, 2013
Latest reply on Aug 19, 2013 by rzufelt
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:

RuntimeError: TextElementObject: Error in setting text


This is my code:

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'


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!

Outcomes