Using arcpy to List Domains Assigned to Featureclass Fields

I was making an edit (adding leading “0”s) to a coded-value domain in an SDE database and realized that my edits were changing the order of the rows of my domain.  Rows were moved to the bottom of the list when they were edited.

So I went through the process of converting my domain back to a table, made my edits in Access and exported the rows to a .dbf in the order I wanted them.

I removed the domain from the field I knew it was assigned to but when I tried to delete the domain, I received an error (The domain is used as a default domain).

The Google Machine led me to an ArcForums post by  with some python code for listing all the fields with a domain.

I tweaked the original a bit, first because it was only examining feature classes in a feature dataset, not stand-alone feature datasets.  And secondly, I updated it to use arcpy.  I posted both the 9.3 version and the 10.0 version, but here is a quick look.  The key addition is the ‘listfc(“”)’ line that is the first line of the def listds() module.

import arcpy

min_workspace = "C:\\Users\\mranter\\AppData\\Roaming\\ESRI\\Desktop10.0\\ArcCatalog\\min.minstaff.sde"
#min_workspace = "C:\\TEMP\\kurst-10.mdb"

arcpy.env.workspace = infgdb

def listfc(inDataset):
featureclasses = arcpy.ListFeatureClasses("","",inDataset)
for f in featureclasses:
print "feature class: ",f


for lf in lfields:
if lf.domain<>"":
print "      domain",f,, lf.domain

def listds():


datasets=arcpy.ListDatasets ("","")
for d in datasets:
print "  dataset: ",d




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s