Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 @ http://www.google.com.au/url?sa=t&source=web&cd=3&ved=0CCMQFjAC&url=http%3A%2F%2Fproceedings.esri.com%2Fdvd%2Fuc%2F2010%2Fuc-index%2Fuc%2Fworkshops%2Ftw_1433.pdf&ei=2R3STZmoAefTiAKT9oTyCg&usg=AFQjCNH-wFZb1mgpnWrV1QKQD5ynZtikfg&sig2=UBLu89hwpAx72djEJggFJg

import arcpy findText=arcpy.GetParameterAsText(0) replaceText=arcpy.GetParameterAsText(1) mxd=arcpy.mapping.MapDocument("Current") 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.

Thanks,

share|improve this question
    
You should delete your previous answer on this question, gis.stackexchange.com/questions/5674/… –  Andy W May 17 '11 at 12:51
    
Andy, that post is a different script which has the required functionality but isn't working...so 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

1 Answer 1

up vote 1 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

Your Answer

 
discard

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.