Hi everyone,
I am looking to return the subtype domains associated with a subtype field. I was able to explore arcpy.da.ListSubtypes however this function seems to return a dictionary and I seem to be getting lost thereafter. Is there a quick way to isolate only the subtype domains from the dictionary?
Thanks!
Solved! Go to Solution.
There is a good sample on the resource center that will list all the fields, their default value, and any domain assigned.
import arcpy
fc = <FeatureClass>
subtypes = arcpy.da.ListSubtypes(fc)
for stcode, stdict in subtypes.iteritems():
print('Code: {0}'.format(stcode))
for stkey in stdict.iterkeys():
if stkey == 'FieldValues':
print('Fields:')
fields = stdict[stkey]
for field, fieldvals in fields.iteritems():
print(' --Field name: {0}'.format(field))
print(' --Field default value: {0}'.format(fieldvals[0]))
if not fieldvals[1] is None:
print(' --Domain name: {0}'.format(fieldvals[1].name))
else:
print('{0}: {1}'.format(stkey, stdict[stkey]))However, if you are only interested in a list of all the domains used within the subtype, we can just list the domains using a similar code:
import arcpy
fc = <FeatureClass>
subtypes = arcpy.da.ListSubtypes(fc)
for stcode, stdict in subtypes.iteritems():
print('Code: {0}'.format(stcode))
for stkey in stdict.iterkeys():
if stkey == 'FieldValues':
print('Fields with Domains:')
fields = stdict[stkey]
for field, fieldvals in fields.iteritems():
if not fieldvals[1] is None:
print(' --Field name: {0}'.format(field))
print(' --Domain name: {0}\n'.format(fieldvals[1].name))
else:
print('{0}: {1}'.format(stkey, stdict[stkey]))Output:
Code: 1 Default: True Name: Metal Pipe SubtypeField: SubTypeCD Fields: --Field name: InletWallThickness --Domain name: fcNumericWallThickness --Field name: Material --Domain name: fcMetalMaterial --Field name: PipeDistributor --Domain name: fcPipeDistributor
There is a good sample on the resource center that will list all the fields, their default value, and any domain assigned.
import arcpy
fc = <FeatureClass>
subtypes = arcpy.da.ListSubtypes(fc)
for stcode, stdict in subtypes.iteritems():
print('Code: {0}'.format(stcode))
for stkey in stdict.iterkeys():
if stkey == 'FieldValues':
print('Fields:')
fields = stdict[stkey]
for field, fieldvals in fields.iteritems():
print(' --Field name: {0}'.format(field))
print(' --Field default value: {0}'.format(fieldvals[0]))
if not fieldvals[1] is None:
print(' --Domain name: {0}'.format(fieldvals[1].name))
else:
print('{0}: {1}'.format(stkey, stdict[stkey]))However, if you are only interested in a list of all the domains used within the subtype, we can just list the domains using a similar code:
import arcpy
fc = <FeatureClass>
subtypes = arcpy.da.ListSubtypes(fc)
for stcode, stdict in subtypes.iteritems():
print('Code: {0}'.format(stcode))
for stkey in stdict.iterkeys():
if stkey == 'FieldValues':
print('Fields with Domains:')
fields = stdict[stkey]
for field, fieldvals in fields.iteritems():
if not fieldvals[1] is None:
print(' --Field name: {0}'.format(field))
print(' --Domain name: {0}\n'.format(fieldvals[1].name))
else:
print('{0}: {1}'.format(stkey, stdict[stkey]))Output:
Code: 1 Default: True Name: Metal Pipe SubtypeField: SubTypeCD Fields: --Field name: InletWallThickness --Domain name: fcNumericWallThickness --Field name: Material --Domain name: fcMetalMaterial --Field name: PipeDistributor --Domain name: fcPipeDistributor
thank you!
Hi, hoping that you are in good health. I need your support to review below code. Using ESRI ArcGIS Desktop version 10.4.1, a file Geodatabase having line feature class "Trench" with two tables "T_DUCT" and "T_SUB_DUCT".
Requirement: It is required to create sub type records of "T_DUCT" inside T_SUB_DUCT (as ROWS). Is there anything need to update in below code?
I have attached the code file.
Regards.
Khalid Mahmood
Riyadh, Saudi Arabia
kmc786pak@gmail.com
The logic of this code is still sound, users will just need to replace instances of .iteritems(), iterkeys(), with .items() and .keys() for ArcPro/Python3 processing.