ArcGIS 10.1+ lets you easily put dynamically populated text boxes in your print layouts. Doing so puts some text in the text element that looks something like this:

<dyn type="page" property="attribute" field="sampleTable.sampleAttribute"domainlookup="true"/>

It works fine for me when I have it just pulls from the index feature class. My problem is that I have data in other feature classes in the same database that need to be joined to the index layer so I can pull relevant attributes out of there and display them in other text elements. As soon as I join one of those feature classes to the index feature class the domain lookup no longer works regardless of what it is set to. That is to say I only get the coded values in my text elements. ESRI has logged this bug (#NIM104451), but I need a workaround sooner than when (if) they get around to fixing it.

My first thought was to use some python to take care of this, but it's getting more unwieldy the more I think about it. My general thought process is this:

  • Make sure the text elements I want to use share the name of the domain they will pull from
  • List layout elements
    List domains in the database
  • For every layout element, step through the domain list until the domain equals the element name
  • Take the current element text (the coded value) and replace it with the equivalent description from the domain

I got this far in my code before thinking there has to be a more efficient way:

import arcpy
mxd = samplemxd

domains = arcpy.da.ListDomains("Database Connections\\database.sde")

Elements = arcpy.listlayoutelements(mxd)

For elem in Elements:
    for dmn in domains:
        if elem.name == dmn.name:
            coded_values = domain.codedValues
            for val, desc in coded_values.iteritems():
                if val == !layer.attribute!
                    elem.text = desc

Any ideas? I'm open to non-python ideas as well, in case there's something database side I can do.

  • +1 for including an NIM number but is there any chance that you can include the name and description of that here too? – PolyGeo Aug 21 '14 at 21:29
  • The code doesn't seem like it would be far off the mark, though you should declare coded_values outside the loop. – Sleep6 Aug 21 '14 at 21:40
  • Thanks for the responses. Here is the ESRI bug page. It says the version is 10.2.2, but I also recreated the same behavior on 10.2.1 and 10.1. – SVisovsky Aug 22 '14 at 0:50
  • After playing around with the above script a bit (including gratuitous use of print statements) I discovered that trying to access the text element like this is not helpful for my purposes. The text element contains only the formatting string and you can't grab the attribute it is dynamically pulling from this way. Time to rethink. – SVisovsky Aug 26 '14 at 19:15

Okay, posting for posterity's sake now.

My team and I did find a way to successfully implement data driven pages with domain values (for the ultimate purpose of a printing service) using a combination of python and spatial views that were created in the database. Basically, every field I wanted on the print layout was included in the spatial view. The python still looped through element names and domain lists as I described above.

The problem with this is that it's abominably slow. We didn't want our end users to wait a solid minute or more (depending on number of pages) for any response from the print button.

The eventual solution we settled on is much simpler and faster. We have the print button generating an html page that pulls data from the database and formats it in pretty much an exact replica of the .mxd we were using. For the map it uses a function on the rest endpoint to generate an image from the map service.


Maybe try a nested dictionary since domain.codedValues returns a dictionary:

domains = arcpy.da.ListDomains("Database Connections\\database.sde")
domain_dict = {}
for domain in domains:
Elements = arcpy.listlayoutelements(mxd)
For elem in Elements:
    code = elem.text
    elem.text = domain_dict[elem.name][code]

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.