2

Using ArcPy (or ArcObjects if essential), is there a way to retrieve the rendered text of a text element that includes Dynamic Text?

The text property of the TextElement includes the Dynamic Text tags, but I would like to access the resolved text that will be displayed on the map.

For example for a title page at the moment:

myTextElement.text = "Country Map - Name: <dyn type="page" property="name"/>
                     - Code: <dyn type="page" property="attribute" field="CNTR_ID"/>"

But I'd like to get the resolved dynamic text, in this example from a data driven page:

Country Map - Name: Zimbabwe - Code: ZW

This is to be able to export metadata for maps produced using data driven pages. At the moment without a method to access the resolved value of the dynamic text the only solutions we can think of are to either;

  1. Write a class to parse and resolve the dynamic text.

This wouldn't be too difficult to do as the datadriven page class includes a property to the index layer, but I expect running an attribute cursor for each page would slow exports down.

  1. Save the MXD for ArcMap 9.3 which doesn't support dynamic text (this strips the dynamic text from the layout and replaces it with it's values).

While this would work it seems a long way around, as after saving a copy the map document would then need to be opened to retrieve the text element value.

2
  • #1 might be possible without running a cursor for each page, but rather running a cursor once to determine what the dynamic text would be for every page, and then output that value with each page.
    – Midavalo
    Commented Jun 5, 2016 at 21:56
  • Thanks Midavalo - that would be a good way of doing it, and then searching for and parsing the dynamic text XML would be the bottleneck but possibly not overly so.
    – kes
    Commented Jun 6, 2016 at 9:07

1 Answer 1

1

It doesn't seem that this is supported directly in the ArcObjects API.

As a workaround using the save to v9.3 route could be slow, but how slow and does it actually matter? For example let's guess it added 10sec per export. That could be annoying yes, but I'd argue that being able to use dynamic text in your mxd would save you more than 10sec in the making of many maps.

I'd suggest that the save to v9.3 is the low risk option. There are a fixed number of steps to the procedure which would need implementing but it would then work for every combination of dynamic text.

Parsing the text, if done right, would probably execute quicker. However parsing markup can be notoriously hard. There are a large number of different elements to cater for. For each element there are a lot of different formatting instructions. That is a lot of combinations if you want to test them exhaustively. See these links for the actual list of elements and formatting instructions; "Working With Dynamic Text" and "Using Dynamic Text With Data Driven Pages"

Whichever you implement, put it behind an interface. Then you can change your mind at a later date without needing to change client code.

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.