AnsweredAssumed Answered

Can't update TextElement text

Question asked by jbrengel on Jul 11, 2018
Latest reply on Jul 17, 2018 by rvburton

I've read just about every post on the internet about updating and/or adding TextElements using arcpy.  I am not able to get the text in my TextElement object to update.

 

The portion of my script is:

 

 

pop_cent = ('Harrisburg', 'Middletown', 'Hershey', 'Halifax', 'Elizabethville')


    if os.path.exists(newpath) == False:
        mxd = arcpy.mapping.MapDocument(inpath) #Create map document object using basemap
        mxd.saveACopy(newpath) # Copy the basemap from Adams for adding appropriate data

        copy_mxd = arcpy.mapping.MapDocument(newpath) # Create map document object using copied basemap
        df = arcpy.mapping.ListDataFrames(copy_mxd, "Layers")[0] #lists the dataframe object to use in AddLayer
        x = df.elementPositionX
        print x
        y = df.elementPositionY
        print y
      
        orig_text = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")
        for d, pop in enumerate(pop_cent):
            orig_text[d].text = pop_cent[d]
            print(orig_text[d].text)
            orig_text[d].elementPositionX = x
            orig_text[d].elementPositionY = y
            arcpy.RefreshActiveView()

 

The script successfully moves the TextElement to where I want in the "copy_mxd" and the print statement in line 18 provides the correct string from pop_cent.  But, the actual TextElement's text does not update the text.  Why?

 

Based on what I've read online, is it because not all the TextElements are embedded in a focused dataframe?  Or perhaps I'm trying to go between two different map documents (mxd and copy_mxd) with TextElements?  Or do I need to somehow access the LayoutView using the mapping module?

 

Thank you,

 

Josh

 

PS Using ArcMap 10.4 on Windows 7, Python 32-bit.

Outcomes