Skip to content

Instantly share code, notes, and snippets.

@steveoh
Last active July 11, 2020 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveoh/e4dd3b0ce0a7d67174592ec3f604fdf7 to your computer and use it in GitHub Desktop.
Save steveoh/e4dd3b0ce0a7d67174592ec3f604fdf7 to your computer and use it in GitHub Desktop.
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