Need to list alll domains in a GeoDatabase (ArcGIS 10)

3994
4
12-01-2011 12:46 PM
RandyKreuziger
Regular Contributor
Is there a geoprocessing tool that will bring back a list of domains within a geodatabase? 

I'd then like to loop through a list of all the domain values.  Then I can programmatically export all domains to tables both for documentation purpose of documenting and also as a means of comparing the same domain from two different geodatabases.
Tags (2)
4 Replies
StephanieWendel
Esri Contributor
There isn't an actual tool; however, python can access the workspace properties in order to examine the domains associated with that workspace. Check out this link on the workspace properties. The domain property will automatically make a list object and you can use a For loop to sort through those and do whatever you need to do to the domains, such as running each domain through the Domain to Table tool.

I hope that helps!
KarenFolger
Occasional Contributor II

This code works.It will create a table in an SDE database - recreating it each time. Lists all the domains used in the workspace.

import arcpy
inWorkspaceString = arcpy.GetParameterAsText(0)
arcpy.env.workspace = inWorkspaceString
outTable = "OTHER_ListDomains_tbl"

# Delete old and Create new output table each time
if arcpy.Exists(outTable):
   arcpy.Delete_management(outTable)
#
arcpy.CreateTable_management(inWorkspaceString, outTable)
arcpy.AddField_management(outTable, "DomainName", "TEXT", "", "", 255, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(outTable, "Versioned", "TEXT", "", "", 1, "", "NULLABLE", "NON_REQUIRED")
#
newRows = arcpy.InsertCursor(outTable, "") # Create cursor to store new rows for output table
arcpy.MakeTableView_management(outTable, "outTableView", "", "", "") # Create table view for output table (for searching for existing records)
#
# Create list of domains
desc = arcpy.Describe(inWorkspaceString)
domains = desc.domains
domains.sort() # Sorts list
for domain in domains:
# Write items from list to output table if they don't already exist there
   arcpy.SelectLayerByAttribute_management("outTableView", "NEW_SELECTION", "\"DomainName\" = \'" + domain + "\'")
   if int(arcpy.GetCount_management("outTableView").getOutput(0)) == 0:
      newRow = newRows.newRow()
      newRow.DomainName = domain
      newRows.insertRow(newRow)
del newRows # Removes lock on output table

BlakeTerhune
MVP Regular Contributor

Since this discussion was created in 2011, ListDomains—Help | ArcGIS Desktop is probably the best way to get this information in 2017 using Python.

JoshuaSchwartz
New Contributor III

I realize this is a very old thread, but I can't recommend enough X-ray for ArcCatalog for exactly this.