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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 7, 2021 at 18:48
2
  • 1
    What do you mean by "domain usage"? 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? 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)
answered Oct 12, 2021 at 1:12
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))
TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
answered Sep 8, 2023 at 6:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.