ArcGIS Pro – Exporting All Domains to Table Using ArcPy

arcgis-proarcpydomains

I want to export all domains from gdb to table. I know that i can do run domain to table tool but it will only export values of that domain.
I also know that there is a batch option but even for that you need to know domain names.

I used to have a python script for that but that was in ArcPy not ArcGIS pro python. I was searching through different blogs but havent found anything yet.

Has anyone tried it on ArcGIS Pro?

Best Answer

With only a couple very small changes to the code here: https://community.esri.com/thread/163889, this runs fine in ArcGIS Pro. (note, the code specifically works against CodedValue, not Range. You'd need to modify if you want Range)

arcpy.env.workspace = "C:\\prj\\MyProject1\\MyProject1.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.items():  
             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) )

Output in addition to the fdgb table output:

Exporting testcodedomain1 coded values to table in C:\prj\MyProject1\MyProject1.gdb
The coded values / descriptions are
aa : sdfsd
rangedomain not a coded value domain. Passing it up.
Exporting testcodedomain2 coded values to table in C:\prj\MyProject1\MyProject1.gdb
The coded values / descriptions are
a : bbb
c : dddd
Related Question