I am trying to create a text label for a series of maps over time. I have a text box with the element name "DateBox" in my mxd. As a filler, it says "Week # here". I want to it say "Week XX", where XX refers to the week number. I am using arcgis 10.3.

I have tried:

import arcpy
from arcpy import env 
env.workspace = r"C:\Users\GIS_User\Output"
map_mxd = arcpy.mapping.MapDocument(r"C:\Users\GIS_User\Output\timelapse.mxd")

for XX in range(1,121): 
    for TextElement in arcpy.mapping.ListLayoutElements(map_mxd, "TEXT_ELEMENT"):
        if TextElementName == "DateBox":
            TextElement.text = 'Week ' + str(XX)
        print TextElement.text

The arcpy window in ArcMap prints the text and shows that it successfully loops from Week 1 to Week 120. However, this change is not reflected in the textbox of the map document. The textbox itself still holds my original filler text "Week # here" and shows no changes when I run this code.

  • 1
    remember to use map_mxd.save() to save your MXD after the script is run. Or use arcpy.mapping.MapDocument("CURRENT") to run it on the currently open MXD.
    – Midavalo
    Commented May 24, 2016 at 20:52

1 Answer 1


Assuming that you are using the "CURRENT" map I think what you may be missing is:


at the end of each iteration.

  • arcpy.RefreshActiveView() worked to refresh the view, but did not produce any changes in the displayed text. I am trying to incorporate either arcpy.mapping.MapDocument("CURRENT") or map_mxd.save() into the loop. The first runs but produces no changes, while the second gives me this error:
    – Mon Mo
    Commented May 25, 2016 at 0:26
  • Traceback (most recent call last): File "<string>", line 8, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_ return fn(*args, **kw) File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\_mapping.py", line 850, in save return convertArcObjectToPythonObject(self._arc_object.save(*gp_fixargs((), True))) IOError: MapDocObject: Unable to save. Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.
    – Mon Mo
    Commented May 25, 2016 at 0:29
  • @MonMo That sounds like a new question because it would seem to be using a different code snippet to the one presented in this question. Consequently, I think you should research/ask it separately.
    – PolyGeo
    Commented May 25, 2016 at 0:43
  • Okay, thanks for the feedback. I think it has something to do with transferring the mxd file to a new computer a while back, but you're right, it is a separate topic.
    – Mon Mo
    Commented May 25, 2016 at 1:15
  • Turns out, map_mxd.save() was not needed. The text on the display was not changing, but checking a jpg export of the map showed that arcpy.RefreshActiveView() worked and the text had the appropriate week numbers when the jpg files were viewed separately.
    – Mon Mo
    Commented May 25, 2016 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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