Skip to content

Instantly share code, notes, and snippets.

@steveoh steveoh/unused_domains.py
Last active Mar 13, 2019

Embed
What would you like to do?
list usused domains and fields with domain
from pprint import pprint
import arcpy
arcpy.env.workspace = r'stage.sde'
output = {}
tables = []
for dirpath, dirnames, walked_tables in arcpy.da.Walk(datatype=['FeatureClass', 'Table']):
#: filter for tables owned by the user
tables += walked_tables
domain_names = set([x.name for x in arcpy.da.ListDomains()])
used_domains = set([])
for table in tables:
print('inspecting ' + table)
domains = {}
for field in arcpy.ListFields(table):
print(' inspecting ' + field.name)
if field.domain:
print(' field has domain ' + field.domain)
domains[field.name] = field.domain
used_domains.add(field.domain)
if len(domains.keys()) > 0:
output[table] = domains
print('unused domains')
pprint(domain_names - used_domains)
print('fields with domains')
pprint(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.