2

I've attempted to write a script that will export all the coded value domains in a geodatabase to a table. Before I dig in the to script and what's wrong, I have looked at the similar question on this topic, but that script would not run for me. Here is my code:

import arcpy

arcpy.env.workspace = r"F:\ITree"
gdb = r"ITree.gdb"
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.codedValues
         print "The coded values / descriptions are"
         for value, descrip in coded_value_list.iteritems():
             print "{0} : {1}".format(value, descrip)
         out_table_name = domain_name.lower()
         #arcpy.DomainToTable_management(gdb, domain_name, out_table_name, "item", "descrip")
     else:
         print "{0} not a coded value domain. Passing it up.".format(domain.name)

When I comment out the Domain to Table, the script runs and produces, this:

Exporting LANDUSE coded values to table in ITree.gdb
The coded values / descriptions are
1 : Single family residential
0 : Not entered
3 : Small commercial
2 : Multi-family residential
5 : Park/vacant/other
4 : Industrial/Large commercial

However, when I uncomment the Domain to Table, it produces the following error:

Exporting LANDUSE coded values to table in ITree.gdb
The coded values / descriptions are
1 : Single family residential
0 : Not entered
3 : Small commercial
2 : Multi-family residential
5 : Park/vacant/other
4 : Industrial/Large commercial
Traceback (most recent call last):
  File "E:/Work/MDC/GISData/MOTools/Scripts/export_gdb_domains.py", line 29, in <module>
    arcpy.DomainToTable_management(gdb, domain_name, out_table_name, "item", "descrip")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 1491, in DomainToTable
    raise e
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Failed to execute (DomainToTable).

It also produces the first table from the domain, but does not copy the coded values and creates an empty table. I've looked through the help documents for Domain to Table (Data Management) and List Domains, but I cannot figure out why it's throwing an error. Clearly something is off in the Domain to Table function, but I can't figure out what, especially since it prints all the parameters correctly.

Using ArcGIS 10.3 and PyCharm Community 4.0.5 with Python 2.7.9

4
  • 1
    Are you running this from command line or in the Python shell in ArcMap? The first parameter in the domaintotable_management, try setting it to the full directory path r"F:\ITree.gdb". The 99999 errors are a pain and very arbitrary. If you are running from command line, I've seen issues on certain machines where you set the enviornment and workspace, and then some how they get changed.
    – branchini
    Commented Aug 14, 2015 at 23:15
  • I'm running it in PyCharm. I changed the gdb variable to the full path: F:\ITree\ITree.gdb and got the same error.
    – tpdance
    Commented Aug 14, 2015 at 23:30
  • I agree with @branchini that this is almost certainly due to the way that you are using arcpy.env.workspace in conjunction with a gdb variable. I would set arcpy.env.workspace = r"F:\ITree.gdb" and dispense with using the gdb variable because you can recall that using arcpy.env.workspace instead.
    – PolyGeo
    Commented Aug 15, 2015 at 0:15
  • Thanks @PolyGeo. That did the trick. I'll post the amended code as an answer. Thanks for all your help!
    – tpdance
    Commented Aug 15, 2015 at 0:55

1 Answer 1

1

Thanks to @branchini and @PolyGeo for the advice. Below is the amended code. I changed the workspace to the full path of the geodatabase and changed the gdb variable to the workspace.

import arcpy

arcpy.env.workspace = r"F:\ITree\ITree.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.codedValues
         print "The coded values / descriptions are"
         for value, descrip in coded_value_list.iteritems():
             print "{0} : {1}".format(value, descrip)
         out_table_name = domain_name.lower()
         arcpy.DomainToTable_management(gdb, domain_name, out_table_name, "item", "descrip")
     else:
         print "{0} not a coded value domain. Passing it up.".format(domain.name)

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.