0

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?

2
  • 1
    What do you mean by "domain usage"?
    – Hornbydd
    Commented Oct 8, 2021 at 0:19
  • 2
    Do you perhaps mean a list of feature class and/or table fields that are constrained by each domain?
    – PolyGeo
    Commented Oct 8, 2021 at 7:27

2 Answers 2

1

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)
0
import arcpy
ws = r'C:\\data\\water.gdb'
domains = arcpy.da.ListDomains(ws)
for domain in domains:
    print('Domain name: {0}'.format(domain.name))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.