I needed to dump all of the domains in my file geodatabase so missing values can be identified. The script runs fine if the domain name has no spaces but, unfortunately this one has many multi-word domain names. Renaming the domains isn't practical and ModelBuilder is not an option. I can list (ListDomains) all of the domains, regardless of the name and loop through everyone of them. The Toolbox version successfully but there are too many domains for that. Here is the script.

import arcpy

domains = arcpy.da.ListDomains(pathname)

fileout = open('filename', 'w')

for domain in domains:

    name = domain.name


    txtline = name,'\n'


    arcpy.DomainToTable_management(inTable,name,outTable + name,"Code","Description")

New contributor
  • Which version of ArcGIS? – KHibma Aug 12 at 12:52
  • ArcGIS 10.6, Pro 2.3 – scramjet Aug 12 at 13:00
  • 2,4 is newest, if you can't update and try that I'd suggest sending this directly to Tech Support. It obviously shouldn't crash, so it sounds like it might be a bug. – KHibma Aug 12 at 13:24
  • 1
    What's the error? – Emil Brundage Aug 12 at 23:01

I'd make use of Validate Table Name and GISPro's Alter Domain. You can alter your domain names using Validate Table Name to remove spaces.

Untested since I don't have ArcGIS Pro:

inGdb = r"Domained\gdb"
outGdb = r"output\gdb"

print ("importing")
import arcpy
import os

print ("listing domains")
domains = [d.name for d in arcpy.da.ListDomains (inGdb)]
for dom in domains:
    print (dom)
    #get valid table name
    altDom = arcpy.ValidateTableName (dom, outGdb)
    print (altDom)
    if altDom != dom:
        #alter domain to valid name
        arcpy.AlterDomain_management (inGdb, dom, altDom)
    outTab = os.path.join (outGdb, altDom)
    arcpy.DomainToTable_management (inGdb, altDom, outTab, "Code", "Description")
    if altDom != dom:
        #alter name back to original
        arcpy.AlterDomain_management (inGdb, altDom, dom)

Your Answer

scramjet is a new contributor. Be nice, and check out our Code of Conduct.

