Just wondering if we can read dynamic text in arcpy?

For example, assume we have a Text Element called myText which contains a piece of dynamic text Map <dyn type="page" property="index"/>. Reading this Text Element is as below:

text = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "myText")[0].text

text is now a string of Map <dyn type="page" property="index"/> which is not what I actually want. In ArcMap, this Text Element is showed as Map 1, and this is the value I want for my text variable.

Is there any simple way to achieve this with arcpy?

As suggested in Access resolved/rendered dynamic text from ArcPy or ArcObjects?, this can be done by either parsing the text (which is not easy to do properly) or saving the mxd to v9.3 (which would slow down the process and may pose a compatibility risk)


Decided to go ahead with parsing the text as the dynamic texts in my MXDs are not that complicated. Cannot afford the approach of saving the mxd to v9.3 due to the huge number of MXDs to deal with.

Anyway, any other suggestions are more than welcome.

  • What is "index" assigned to property? Is it a field name? – ahmadhanb Mar 20 at 7:03
  • @ahmadhanb, please read here to understand what "index" stands for in dynamic text. – Kevin Mar 20 at 7:36

There is no way to see the information directly using dynamic text, but you can get the same information using the following arcpy code:

"Page {0} of {1}".format(mapdoc.dataDrivenPages.currentPageID,mapdoc.dataDrivenPages.pageCount)

This will produce the following information which exactly what is written in the dynamic text:

'Page 2 of 20'

enter image description here

When you click the next page and rerun the code it will give the exact page number shown in the dynamic text:

enter image description here

  • So you suggest parsing the text as in Access resolved/rendered dynamic text from ArcPy or ArcObjects?. As mentioned in the question, it's doable, but will not be an easy task if you're processing thousands of mxds each has its own dynamic text which is different from others. – Kevin Mar 20 at 7:55
  • I agree with you, but I think this is the only way you have because the dynamic text doesn't have the method to access the rendered text. – ahmadhanb Mar 20 at 8:02
  • You're probably right. Let's wait for a while to see if anyone comes up with a new approach. – Kevin Mar 20 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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