Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to update misc text in an active map window but can't seem to crack the code and I found some presentations that mention it can be done but the full code isn't there.

The following is from an ESRI presentation @

import arcpy
for textElm in arcpy.mapping.ListLayoutElements(mxd,"TEXT_ELEMENT"):
    if findText in textElm.text:
        textElm.text=textElm.text.replace(findText, replaceText)

I want to be able to enter text string "This is the old text" and replace with "this is the replacement text"

Simple find-->replace that word or notepad does but in an active ArcMap.

share|improve this question
You should delete your previous answer on this question,… – Andy W May 17 '11 at 12:51
Andy, that post is a different script which has the required functionality but isn't the two may help someone advise me on how to get the required full functionality. Best – GeorgeC May 18 '11 at 3:19
if that is the case then you should open that answer as a new question. The format of the site is not to open new questions as answers to other peoples questions. – Andy W May 18 '11 at 3:59
up vote 3 down vote accepted

Here is a PSU link that searches and replaces for a certain text element within a given mxd (code sample below).

# Create a MapDocument object referencing the MXD you want to update
mxd = arcpy.mapping.MapDocument(r"C:\GIS\TownCenter_2009.mxd")

# Loop through each text element in the map document
for textElement in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):

    # Check if the text element contains the out of date text
    if textElement.text == "GIS Services Division 2009":

    # If out of date text is found, replace it with the new text
        textElement.text = "GIS Services Division 2010"
share|improve this answer
Thanks mate. It works great. Do you know if we can modify it to not only accept full match but partial map as well. For example I now have to change "Map Sheet 4 of 19" to "Map Sheet 05 of 19" rather than simply "Sheet 4" to "Sheet 05". Cheers. – GeorgeC May 18 '11 at 0:47
how do you reset your text element to its original? – ziggy Mar 29 at 15:34
@ziggy, one option would be to write the old value(s) to text file or some custom configuration file. When you need to pull in an old value, you could call a custom function to pull the value out of the said file above. – artwork21 Mar 29 at 16:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.