List subtypes Error Returned without Exception

566
1
Jump to solution
08-15-2017 12:59 PM
RachelAlbritton
Occasional Contributor III

I am trying to loop through my entire SDE database to give me a list of all active subtypes. 

I've adapted this script as a starting point. If I specify a unique feature class explicitly, the script works

i.e.

    subtypes = arcpy.da.ListSubtypes(r"\\ad.utah.edu\sys\FM\gis\ags_10_3\ags_content\sde_connection_files\sdeadmin@fm-sqlsrcvrtest.fm.utah.edu.sde\uusd.DBO.Lighting\UUSD.DBO.lighting")

    for stcode, stdict in list(subtypes.items()):
        print('Code: {0}'.format(stcode))
        for stkey in list(stdict.keys()):
            if stkey == 'FieldValues':
                fields = stdict[stkey]
                for field, fieldvals in list(fields.items()):
                    if not fieldvals[1] is None:
                        print fieldvals[1].name
            

 

however, if I loop it through feature classes within feature datasets, it goes those most of them but keeps getting stuck on a specific feature class (the same feature class that does work in the above example).

for fds in arcpy.ListDatasets('*lighting*'):  
        for fc in arcpy.ListFeatureClasses('','',fds):
            print "\n" + fc
            subtypes = arcpy.da.ListSubtypes(fc)
            for stcode, stdict in list(subtypes.items()):
                print('Code: {0}'.format(stcode))
                for stkey in list(stdict.keys()):
                    if stkey == 'FieldValues':
                        fields = stdict[stkey]
                        for field, fieldvals in list(fields.items()):
                            if not fieldvals[1] is None:
                                print fieldvals[1].name
 
PYTHON ERRORS:
Traceback info:
  File "C:\Users\u6003632\Google Drive\GIS_Files\Python\Python_Scripts\print_subtypes.py", line 27, in <module>
    subtypes = arcpy.da.ListSubtypes(fc)

Error Info:
error return without exception set                       ‍‍‍‍‍‍‍‍‍‍‍‍‍

 The feature class is versioned. I'm not sure what the difference is - and why it only throws the error on this fc but it will work when it is a standalone. What the difference? 

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

I don't have time to dig in now, but the issue is likely tied to you having a feature class named the same as a feature dataset.  ListFeatureClasses—Help | ArcGIS Desktop  returns an unqualified list, i.e., just feature class names, not feature dataset and feature class concatenated together.

UPDATE:  Using Walk—Help | ArcGIS Desktop  and the original subtype code:

import os

walk = arcpy.da.Walk(datatype="FeatureClass")  # assumes arcpy.env.workspace is already set to SDE connection

for root, fds, fcs in walk:
    for fc in fcs:
        subtypes = arcpy.da.ListSubtypes(os.path.join(root, fc))
        for stcode, stdict in list(subtypes.items()):
            print('Code: {0}'.format(stcode))
            for stkey in list(stdict.keys()):
                if stkey == 'FieldValues':
                    fields = stdict[stkey]
                    for field, fieldvals in list(fields.items()):
                        if not fieldvals[1] is None:
                            print fieldvals[1].name

View solution in original post

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

I don't have time to dig in now, but the issue is likely tied to you having a feature class named the same as a feature dataset.  ListFeatureClasses—Help | ArcGIS Desktop  returns an unqualified list, i.e., just feature class names, not feature dataset and feature class concatenated together.

UPDATE:  Using Walk—Help | ArcGIS Desktop  and the original subtype code:

import os

walk = arcpy.da.Walk(datatype="FeatureClass")  # assumes arcpy.env.workspace is already set to SDE connection

for root, fds, fcs in walk:
    for fc in fcs:
        subtypes = arcpy.da.ListSubtypes(os.path.join(root, fc))
        for stcode, stdict in list(subtypes.items()):
            print('Code: {0}'.format(stcode))
            for stkey in list(stdict.keys()):
                if stkey == 'FieldValues':
                    fields = stdict[stkey]
                    for field, fieldvals in list(fields.items()):
                        if not fieldvals[1] is None:
                            print fieldvals[1].name
0 Kudos