AnsweredAssumed Answered

000732 Error on GetCount for feature classes

Question asked by banderson_qsi on Apr 27, 2020
Latest reply on Apr 28, 2020 by bixb0012

Hello,

 

I am running into issues deleting empty feature classes from a geodatabase.  The original source code is from this thread: How to delete the empty dataset from gdb.  The error I am encountering is appearing on line 20 when the fc variable is being called to GetCount 

count = GetCount(fc)

 

Error message:

"ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000732: Input Rows: Dataset C:\path\to\folder\geodatabase\featureclass does not exist or is not supported

Failed to execute (GetCount)"

 

The odd thing is the feature class does exist and the error only appears on some file geodatabases. My initial thoughts are there was an issue converting this script into the toolbox as the fgdb variable is set to arcpy.GetParameter(0) - also have tried arcpy.GetParameterasText(0) or just pasting the path directly into the variable as such r'C:\path\to\folder\geodatabase'. Upon debugging, the path to the feature class is correct so no issues there. I've reviewed Error: 000732: Dataset does not exist or is not supported  but none of the workarounds/solutions apply here...

 

This script is run on several different file geodatabases with the same schema.  Some run with no issues at all while other cause this error to appear.  The theory right now is a long path name is causing the issue? I know running geoprocessing tools there seems to be a limit on workspace names and/or the length of the path.  We moved a geodatabase that was causing issues to a shorter path and abbreviated the geodatabase name; afterwords, it worked.  

 

Really curious about what is going on here.  Thanks for the help.

 

def main():
    import arcpy
    import os

    fgdb = r'C:\GeoNet\DeleteEmpty\SSUC_FGDB_V3.gdb'

    # list feature datasets
    arcpy.env.workspace = fgdb
    fdss = arcpy.ListDatasets()
    fdss.append('')

    # loop through feature datasets to delete empty ones
    print("Delete empty featureclasses")
    for fds in fdss:
        print("Processing FDS: {}".format(fds))
        fcs = arcpy.ListFeatureClasses('*', None, fds)
        # loop through featureclasses in feature dataset
        for fc_name in fcs:
            fc = os.path.join(fgdb, fds, fc_name)
            count = GetCount(fc)
            if count == 0:
                # if fc is empty, delete it
                print(" - Deleting: {}".format(fc_name))
                arcpy.Delete_management(fc)
            else:
                print(" - Skip: {}".format(fc_name))

    # delete empty feature datasets
    print("Delete empty feature datasets")
    fdss = arcpy.ListDatasets()
    for fds in fdss:
        print("Processing FDS: {}".format(fds))
        fcs = arcpy.ListFeatureClasses('*', None, fds)
        if len(fcs) == 0:
            print(" - Delete FDS {}".format(fds))
            arcpy.Delete_management(fds)
        else:
            print(" - Keep FDS {}".format(fds))

    # delete empty tables
    print("Delete empty tables")
    tbls = arcpy.ListTables()
    for tbl_name in tbls:
        tbl = os.path.join(fgdb, tbl_name)
        count = GetCount(tbl)
        if count == 0:
            # if tbl is empty, delete it
            print(" - Deleting: {}".format(tbl_name))
            arcpy.Delete_management(tbl)
        else:
            print(" - Skip: {}".format(tbl_name))


def GetCount(fc):
    return int(arcpy.GetCount_management(fc).getOutput(0))

if __name__ == '__main__':
    main()

Outcomes