Select to view content in your preferred language

Python 3 Script Not Executing without Error in ArcGIS Pro 3.1.2 but runs Error Free in ArcMap 10.8.1

3446
10
Jump to solution
05-29-2023 02:40 PM
Zedwards_SIPI
Occasional Contributor

Hello Folks,

I am not a programmer but am getting more and more familiar with ArcPy with ArcGIS Pro these days. I have purchased a digital book that has proven quite useful too. That being said, I am receiving the following error when executing a toolbox script (.py): 

Again, it works fine when run from ArcMap or ArcCatalog and even does what it's supposed to do in Pro but throws the error below .I have also updated my project packages but do get errors when trying to do certain updates or install Spyder from there. Any ideas are much appreciated.

Start Time: Monday, May 29, 2023 3:30:17 PM
NM_wind
ShapeFile
1328
Nothing to Delete
Test
FeatureClass
0
EMPTY VECTOR DATASET DELETED
Traceback (most recent call last):
  File "C:\Users\zach.edwards\OneDrive - Western Data Systems\Documents\AllTerraCentral\Python\ListFCFeaturesRecursivelyCountNameReportDeletezero_PRO.py", line 33, in <module>
    if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 23607, in GetCount
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 23604, in GetCount
    retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.ERROR 000840: The value is not a Table View.ERROR 000840: The value is not a Raster Layer.
Failed to execute (GetCount) 

The actual .py is pasted here below...

import arcpy
import os
 
workspace = arcpy.GetParameterAsText(0)
outFile = open(r"C:\temp\VectorDataList.txt", "a")
shapefiles = []
 
walk = arcpy.da.Walk(workspace, topdown=True, datatype="FeatureClass")
 
for dirpath, dirnames, filenames in walk:
for filename in filenames:
shapefiles.append(os.path.join(dirpath, filename))
for shapefile in shapefiles:
layerName = arcpy.Describe(shapefile).baseName
layerPath = arcpy.Describe(shapefile).path
layerDType = arcpy.Describe(shapefile).dataType
arcpy.AddMessage(layerName)
arcpy.AddMessage(layerDType)
arcpy.MakeFeatureLayer_management (shapefile, layerName)
arcpy.AddMessage(arcpy.GetCount_management(layerName).getOutput(0))
if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
arcpy.Delete_management(shapefile)
arcpy.AddWarning("EMPTY VECTOR DATASET DELETED")
else:
arcpy.AddWarning("Nothing to Delete")
outFile.write("\n" "Filename: ")
outFile.write(layerName)
outFile.write("\n""Path: ")
outFile.write(dirpath)
outFile.write("\n" "DataType: ")
outFile.write(layerDType)
outFile.write("\n" "Feature Count: ")
if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
outFile.write(arcpy.GetCount_management(layerName).getOutput(0))
outFile.write("\n" "EMPTY VECTOR DATASET DELETED")
else:
outFile.write(arcpy.GetCount_management(layerName).getOutput(0))
outFile.write("\n")
outFile.close()
 

 

Tags (2)
0 Kudos
10 Replies
by Anonymous User
Not applicable

Is the file corrupt? If its a shapefile, does it have all the necessary files (shp, dbf, shx) with it? Try getting the count of data before making it a feature layer to see if it's the method or the file.

0 Kudos