Using this code I am able to list all domains inside my GDB
import arcpy
ws = "C:\\data\\water.gdb"
domains = arcpy.da.ListDomains(ws)
for domain in domains:
print('Domain name: {0}'.format(domain.name))
How can I list the domain usage for each of these domains?
asked Oct 7, 2021 at 18:48
-
1What do you mean by "domain usage"?Hornbydd– Hornbydd2021年10月08日 00:19:02 +00:00Commented Oct 8, 2021 at 0:19
-
2Do you perhaps mean a list of feature class and/or table fields that are constrained by each domain?PolyGeo– PolyGeo ♦2021年10月08日 07:27:14 +00:00Commented Oct 8, 2021 at 7:27
2 Answers 2
You could use something like this code to determine what domain is used by what field in a feature class.
import arcpy
ws = "C:\\data\\water.gdb"
arcpy.env.workspace = ws
domains = arcpy.da.ListDomains(ws)
# get the feature datasets
datasets = arcpy.ListDatasets(feature_type = 'Feature')
# append the top level dataset
datasets = [''] + datasets if datasets is not None else []
for domain in domains:
for fd in datasets:
# get the feature classes
fcs = arcpy.ListFeatureClasses(feature_dataset=fd)
for fc in fcs:
fields = arcpy.ListFields(fc)
for field in fields:
if field.domain == domain:
print('Found field ' + field.name + ' in feature class ' + fc + ' using ' + domain)
answered Oct 12, 2021 at 1:12
import arcpy
ws = r'C:\\data\\water.gdb'
domains = arcpy.da.ListDomains(ws)
for domain in domains:
print('Domain name: {0}'.format(domain.name))
TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
lang-py