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
arcpy.env.workspace
in conjunction with agdb
variable. I would setarcpy.env.workspace = r"F:\ITree.gdb"
and dispense with using thegdb
variable because you can recall that usingarcpy.env.workspace
instead.