Why does ESRI's geodatabase not store its built-in "lookup table" object (that it calls a coded value domain) as a simple database table. Instead, coded value domains are stored as binary objects that connot be accessed without going through ArcObjects. This shortcoming becomes a big pain when you start building ArcGIS server applications down the road. Other than trying to keep access to the gdb that much more proprietary, it's hard to understand this design decision.
This script will work from ArcCatalog or ArcMap's VBA Editor. Given a path to a geodatabase (in the example, an .sde connection file) and an output location, the script will output one comma seperated value file (.csv) per coded value type domain in your geodatabase.
'Updated 2/9/09 10:57am
Public Sub ExportCodedValueDomainsToCSVFiles()
Dim gdbLocation as string Dim outputLocation as string Dim pFact As IWorkspaceFactory Dim pWorkspace As IWorkspace Dim pWSDomains As IWorkspaceDomains Dim pEnumDomains As IEnumDomain Dim pDomain As IDomain Dim pCVDomain as ICodedValueDomain Dim cvCount as Long Dim d As Long
'**** SET PARAMETERS gdbLocation = "C:\Documents And Settings\USERNAME\Application Data\ESRI\ArcCatalog\Connection to gdb92.agrc.utah.gov.sde" outputlocation = "C:\temp" '****
'Open Geodatabase From File 'In this case we are connecting to SDE via the connection file saved 'when you make a connection in ArcCatalog or ArcMap Set pFact = New SdeWorkspaceFactory Set pWorkspace = pFact.OpenFromFile(gdbLocation,0)
'Get a pointer to the geodatabase through the workspaceDomains interface Set pWSDomains = pWorkspace 'Query Interface
'Get pointer to domain collection Set pEnumDomains = pWSDomains.Domains
'Loop through each Domain Set pDomain = pEnumDomains.Next Do Until pDomain Is Nothing
'Check to make sure current Domain is Coded Value, not Range Domain If typeof pDomain is ICodedValueDomain then
Set pCVDomain = pDomain 'QUery Interface
Open outputlocation & "\" & pDomain.name & ".csv" for output as #1 Print #1, "CodeVal,DescVal" 'Print field header row cvCount = pCVDomain.CodeCount For d = 0 to cvCOunt -1 Print #1, pCVDomain.Value(d) & "," & pCVDomain.Name(d) Next d close #1