Hello everyone,
I am looking for a script that lists all the domains and Feature Classes or tables where the domain is referenced.
Also I am interested also in passing as a parameter a specific domain name and listing all Feature Classes and Tables where the domain is referenced.
Thanks
Here are a couple of scripts that I have used. This one reads the domain information:
import arcpy
dbName = r"C:\path\to\file.gdb" # your geodatabase path
print dbName
print
domains = arcpy.da.ListDomains(dbName)
for domain in domains:
print
print('Domain name: {0}'.format(domain.name))
if domain.domainType == 'CodedValue':
coded_values = domain.codedValues
for val, desc in sorted(coded_values.iteritems()):
print('{0} : {1}'.format(val, desc))
elif domain.domainType == 'Range':
print('Min: {0}'.format(domain.range[0]))
print('Max: {0}'.format(domain.range[1]))
This one reads the field information. Note specifically the field.domain property.
import arcpy
from arcpy import env
# Set the current workspace
env.workspace = r"C:\path\to\file.gdb" # your geodatabase path
print env.workspace
print
# Get the list of standalone tables in the geodatabase
#
tableList = arcpy.ListFeatureClasses() # for features
# tableList = arcpy.ListTables() # for tables
print tableList
for table in tableList:
print
print table
dbTable = env.workspace + "\\" + table
fieldList = arcpy.ListFields(dbTable)
print '\t['
for field in fieldList:
# print("\t{0} is a type of {1} with a length of {2}"
# .format(field.name, field.type, field.length))
# Print field properties
#
# print("Name: {0}".format(field.name))
# print("\tBaseName: {0}".format(field.baseName))
# print("\tAlias: {0}".format(field.aliasName))
# print("\tLength: {0}".format(field.length))
# print("\tDomain: {0}".format(field.domain))
# print("\tType: {0}".format(field.type))
# print("\tIs Editable: {0}".format(field.editable))
# print("\tIs Nullable: {0}".format(field.isNullable))
# print("\tRequired: {0}".format(field.required))
# print("\tScale: {0}".format(field.scale))
# print("\tPrecision: {0}".format(field.precision))
print '\t["' + field.name + '",',
if (field.type == "String"):
print '"TEXT", ',
print '"' + str(field.length) + '",',
else:
print ("\"{0}\", ".format(field.type).upper()),
print '"#",',
print '"' + field.aliasName + '",',
if len(field.domain):
print '"' + field.domain + '"],',
else:
print '"#",',
print '"#"],' # Default
print '\t]'
# Fields: [ 0:Name, 1:Type, 2:Size, 3:Alias, 4:Domain 5:Default ] use "#" for blanks
# Field type is returned as:
# SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, Blob
See also: