000732 Error on GetCount for feature classes

635
7
Jump to solution
04-27-2020 09:44 AM
BradleyAnderson1
New Contributor II

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()
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Given that ".gdb" is the extension for file geodatabases, naming a non-FGDB folder with that extension is a recipe for issues.  Even if some tools work with it, inevitably some tools will parse the path incorrectly, like what is happening here, and tools will error out.  You could try to open a case with Esri Support, but I suspect they will say not to name folders with ".gdb" extensions.

Since the root cause of the issue has likely been identified, please mark a response as correct or mark the thread as assumed answered to close it out. 

View solution in original post

7 Replies
DavidPike
MVP Frequent Contributor

I think your input needs to be a table view for your getCount function, rather than the feature class.

0 Kudos
BradleyAnderson1
New Contributor II

I appreciate your reply. If I am interpreting you correctly, the GetCount function should be directed to the attribute table of the feature class?  Looking at the examples provided in ArcGIS Help, the sample code uses a feature class in the function:

Would you mind elaborating?

0 Kudos
DavidPike
MVP Frequent Contributor

Of course, 

I've looked at the documentation you sent a link for, that code sample applies to the use of a script in immediate mode i.e. the python window in an mxd, where you have the feature classes represented a layer in your TOC.

I'd suggest adding a line of code in your second for loop to turn each of those feature classes into feature layers, which may work the same as a table view.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Given that the script works fine on some FGDBs and

We moved a geodatabase that was causing issues to a shorter path and abbreviated the geodatabase name; afterwords, it worked.  

I would focus on your paths.  What do some of your problematic paths look like?

0 Kudos
BradleyAnderson1
New Contributor II

Thanks for looking into this.  That was my initial thought as well.   Here is a path that caused the script to throw an error.

C:\Users\username\Desktop\ABCD2020workshop_Section4test\ABC_2002_abcdtrialrun.gdb\ABC_2002_abcdtrialrun.gdb

Yes, I know it is odd that there is a folder named .gdb, but still shouldn't be causing the issue as the output text indicates "Dataset C:\Users\username\Desktop\ABCD2020workshop_Section4test\ABC_2002_abcdtrialrun.gdb\ABC_2002_abcdtrialrun.gdb\FeatureClassWithDataFC2 does not exist or is not supported" which is the correct path.

I'll go check to see if we rename the .gdb folder to see if it continues to throw the error.

0 Kudos
BradleyAnderson1
New Contributor II

The folder path with a folder named "example.gdb" or in the sample above was causing this error to occur.  Haven't developed a way for the script to handle it, but the workaround seems to be renaming the folder.  

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Given that ".gdb" is the extension for file geodatabases, naming a non-FGDB folder with that extension is a recipe for issues.  Even if some tools work with it, inevitably some tools will parse the path incorrectly, like what is happening here, and tools will error out.  You could try to open a case with Esri Support, but I suspect they will say not to name folders with ".gdb" extensions.

Since the root cause of the issue has likely been identified, please mark a response as correct or mark the thread as assumed answered to close it out.