Based off your original post, how would I modify the script so that it can be converted to a tool, with the input being any user defined sde database, and the output being a message with the 'domains_unused'
Here's what I have so far.....it works as a tool, but I do not see the print messages being output under geoprocessing results or some sort of text file message:
import arcpy
import os
#Slightly modified from Geonet thread by Blake Terhune titled 'Delete Unused Domains'
# Set workspace
arcpy.env.workspace = arcpy.GetParameterAsText(0)
# Get domains that are assigned to a field
domains_used = []
for dirpath, dirnames, filenames in arcpy.da.Walk(myGDB, datatype=["FeatureClass", "Table"]):
for filename in filenames:
print "Checking {}".format(os.path.join(dirpath, filename))
try:
## Check for normal field domains
for field in arcpy.ListFields(os.path.join(dirpath, filename)):
if field.domain:
domains_used.append(field.domain)
## Check for domains used in a subtype field
subtypes = arcpy.da.ListSubtypes(os.path.join(dirpath, filename))
for stcode, stdict in subtypes.iteritems():
if stdict["SubtypeField"] != u'':
for field, fieldvals in stdict["FieldValues"].iteritems():
if not fieldvals[1] is None:
domains_used.append(fieldvals[1].name)
except Exception, err:
print "Error:", err
# Get domains that exist in the geodatabase
domains_existing = [dom.name for dom in arcpy.da.ListDomains(myGDB)]
# Find existing domains that are not assigned to a field
domains_unused = set(domains_existing) ^ set(domains_used)
print "{} unused domains in {}".format(len(domains_unused), myGDB)
print domains_unused