Hi, I can't figure out why this won't run. Any of the methods below return ERROR 000732. I just created the geodatabase, and it's the latest version. ListFeatureClasses() will show the layer, but then arcpy.management.MakeFeatureLayer() fails.
There are some other geodatabases on my computer that will work, but I don't know why this one won't. I can export the feature class to a shapefile and then arcpy.management.MakeFeatureLayer will work on that.
#this is a geodatabase feature class. I can view it in ArcGIS, and within Arc I can run MakeFeatureLayer.
input_hydro = "F:\\scratch4\\test.gdb\\hydroTest"
arcpy.env.workspace = os.path.dirname(input_hydro)
ds = arcpy.ListFeatureClasses()
for d in ds:
print(d) #prints HydroTest
input_hydro_FL = arcpy.management.MakeFeatureLayer(in_features=input_hydro, out_layer="hydroOriginal")
input_hydro_FL = arcpy.management.MakeFeatureLayer(in_features=d, out_layer="hydroOriginal")
input_hydro_FL = arcpy.management.MakeFeatureLayer(in_features=os.path.basename(input_hydro, out_layer="hydroOriginal")
input_hydro_FL = arcpy.management.MakeFeatureLayer(in_features=input_hydro, out_layer="hydroOriginal")
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset hydroTest does not exist or is not supported
Failed to execute (MakeFeatureLayer).
don't you want the workspace set to the gdb? not the folder that it is in?
arcpy.env.workspace = "C:/data/base.gdb"not the c:/data folder as an example
os.path.dirname(input_hydro) returns the path to the GDB. When I set that as the workspace, it fails. When I give the full path to the in_features, it also fails. It works fine with some other geodatabases, and also works fine with shapefiles.
I would double check to make sure that feature class exists and there is no extra characters in the name.
Do a simple print out of all the features in the database,
import arcpy
# Set workspace to the geodatabase
gdb_path = r"F:\scratch4\test.gdb"
arcpy.env.workspace = gdb_path
# List all feature classes
feature_classes = arcpy.ListFeatureClasses()
print(f"Geodatabase: {gdb_path}")
print(f"Feature class count: {len(feature_classes)}")
print("=" * 70)
if feature_classes:
print(f"{'No.':<4} {'Name':<30} {'Alias Name':<30}")
print("-" * 70)
for i, fc in enumerate(feature_classes, 1):
try:
# Get the full path to describe
fc_path = f"{gdb_path}\\{fc}" if not "\\" in fc else fc
desc = arcpy.Describe(fc_path)
alias_name = desc.aliasName if hasattr(desc, 'aliasName') else "(no alias)"
print(f"{i:<4} {fc:<30} {alias_name:<30}")
except Exception as e:
print(f"{i:<4} {fc:<30} ERROR: {str(e)[:30]}")
else:
print("No feature classes found.")