import arcpy arcpy.env.workspace = "C:\Workspace\template.gdb"
for FD in arcpy.ListDatasets(): for FC in arcpy.ListFeatureClasses("","",FD): for field in arcpy.ListFields(FC): if field.domain == "D_LABEL_TYP_1": print FC, field.name, field.domain
del FD, FC, field for FC in arcpy.ListFeatureClasses(): for field in arcpy.ListFields(FC): if field.domain == "D_LABEL_TYP_1": print FC, field.name, field.domain
del FC, field for table in arcpy.ListTables(): for field in arcpy.ListFields(table): if field.domain == "D_LABEL_TYP_1": print table, field.name, field.domain
While looking for some problems I've encountered I came across this thread. Not sure if anyone is still "listening" to this thread, but thought I would post some code I have to list subtypes and correnponding default field values (and releted domains in the subtype). Maybe it is useful for someone...
def main():
# import arceditor
import arcpy
import os
lst_amb = ["DLLO 9.3.1", "TEST 9.3.1", "PROD 9.3.1",
"DLLO 10.1", "TEST 10.1", "PROD 10.1"]
# dictionary with connection files
dct_conn = {"DLLO 9.3.1":r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Desarrollo 9.3.1 (GEOGENESIS).sde",
"TEST 9.3.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Pruebas 9.3.1 (GEOGENESIS).sde",
"PROD 9.3.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Produccion 9.3.1 (GEOGENESIS).sde",
"DLLO 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Desarrollo 10.1.sde",
"TEST 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Pruebas 10.1.sde",
"PROD 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Produccion 10.1.sde"}
# set encoding to utf-8
import sys
reload(sys)
print sys.getdefaultencoding()
def_enc = sys.getdefaultencoding()
sys.setdefaultencoding('utf8')
# format of TXT report with subtypes
report = r"D:\Xander\Genesis\Domains\report_subtypes_v4.txt"
with open(report, "w") as f:
f.write("Database\tDataset\tFeatureClass\tSubtypeField\tSubtypeCode\tSubtypeName\tIsDefaultValue\tFieldName\tFieldDefaultValue\tFieldDomain\n")
# loop through databases
for amb in lst_amb:
ws = dct_conn[amb]
arcpy.env.workspace = ws
lst_fds = arcpy.ListDatasets()
# loop through feature datasets
for fds in lst_fds:
fcs = arcpy.ListFeatureClasses(feature_dataset=fds)
if len(fcs) != 0:
# loop through each featureclass en current feature dataset
for fc in fcs:
try:
# list subtypes
subtypes = arcpy.da.ListSubtypes(os.path.join(ws,fds,fc))
# colect info on subtype
for stcode, stdict in subtypes.iteritems():
if 'Default' in stdict:
IsDefaultValue = stdict['Default']
else:
IsDefaultValue = ""
if 'Name' in stdict:
SubtypeName = stdict['Name']
else:
SubtypeName = ""
if 'SubtypeField' in stdict:
SubtypeField = stdict['SubtypeField']
if SubtypeField != None and SubtypeField != "":
# list default field value and field details (like related domain)
if 'FieldValues' in stdict:
fields = stdict['FieldValues']
for fieldname, fieldvals in fields.iteritems():
FieldDefaultValue = fieldvals[0]
if not fieldvals[1] is None:
domainname = fieldvals[1].name
else:
domainname = ""
f.write('{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\n'.format(
amb, fds, fc, SubtypeField, stcode, SubtypeName, IsDefaultValue,
fieldname, FieldDefaultValue, domainname))
except:
f.write('{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\n'.format(
amb, fds, fc, "Error", -1, "Error", "Error",
"Error", -1, "Error"))
# restore default settings
sys.setdefaultencoding(def_enc)
if __name__ == '__main__':
main()
Kind regards, Xander
It'd be great if someone handy with Python demonstrates how to the domains associated with each subtype in each feature class.
Also: the ArcGIS Ideas site has an idea to create a "Locate Domain" tool. This would make life easier for those of us who work with lots of field and/or subtype domains:
https://c.na9.visual.force.com/apex/ideaView?id=08730000000c1vSAAQ