Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

TexElementObject: Error in setting text

$
0
0
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:

Code:

RuntimeError: TextElementObject: Error in setting text
This is my code:

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!

Viewing all articles
Browse latest Browse all 2485

Trending Articles