I am new to Python. I'm trying to gather a list of all of our Domains (we have a lot) and their coded values and export them into a table or a format that can easily be put into a table. I've had luck getting the domains and the coded values by using ListDomains. I want that information outputted into a table and that's where I'm stuck.

Here's the code I've been using (based off of example found here):

import arcpy

arcpy.env.workspace = r"C:\folder\domains.gdb"
gdb = arcpy.env.workspace
arcpy.env.overwriteOutput = True  

domains = arcpy.da.ListDomains(gdb)

for domain in domains:
     if domain.domainType == 'CodedValue':
         domain_name = domain.name
         print 'Exporting {0} coded values to table in {1}'.format(domain_name, gdb)
         coded_value_list = domain.codedValue
         print "The coded values / descriptions are"
         for value, descrip in coded_value_list.items():
             print "{0} : {1}".format(value, descrip)
         out_table_name = domain_name.lower()
         arcpy.DomainToTable_management(gdb, domain_name, out_table_name, "item", "descrip")
         print "{0} not a coded value domain. Passing it up.".format(domain.name)

The error I get after running that is":

Exporting YesNo coded values to table in C:\folder\domains.gdb

    Traceback (most recent call last):
      File "C:\Users\name\place\domain6", line 14, in <module>
        coded_value_list = domain.codedValue
    AttributeError: 'Workspace Domain object' object has no attribute 'codedValue'

How can I simply export a readable table of all the domains and coded values?

Your Answer

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

Browse other questions tagged or ask your own question.