File doesn't exist/isn't supported - C# .NET ArcObjects Python Combo

861
1
02-17-2018 08:52 AM
MKF62
by
Occasional Contributor III

I have a script that is run using a combination of ArcObjects and a python script. The process starts in C# Arcobjects code, I create a geoprocessor, and then I run a toolbox tool (python script) with uploaded data from the user. The data is uploading successfully, I can see it in file explorer, however my python script says it doesn't exist. Now if I go in the python IDE, the script runs just fine there using the same file in the same location. I'm not sure what's going on.

This sets up the toolbox and passes the file geodatabase to the toolbox tool and runs it:

 //Set up HabitatClassification script
 IGeoProcessorResult result;
 IGeoProcessor2 gp = new GeoProcessor() as IGeoProcessor2;
 string tlbxPath = Server.MapPath("~/ArcToolbox/HabitatMon.tbx");
 gp.AddToolbox(@tlbxPath);
 IVariantArray parameters = new VarArray();
 parameters.Add(geodatabase);

 //Run Habitat Classification script
 try
 {
   result = gp.Execute("HabitatClassification", parameters, null);
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Now that I have passed the file geodatabase into the tool, in the python script, I set up the workspace and get the list of feature classes in the FGDB. It perform this step just fine, so clearly it can find the feature class I am looking for and it does, indeed, exist. 

#Get user uploaded geodatabase and set the workspace to it
uploadedGDB = sys.argv[1]
arcpy.env.workspace = uploadedGDB

#Get the patch feature class out of the geodatabase. Make sure the list created is not empty and that there
#is only one feature class within it.
patchfc = arcpy.ListFeatureClasses("*Patch*")
svyPtFC = uploadedGDB + r"\{0}".format(patchfc[0])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

At this point in time, "svyPtFC" looks like this:

C:\Users\xxx\Desktop\GIS_NET_Testing\ArcObjectsTesting\ArcObjects\UploadedFiles\NETTesting.gdb_02_17_2018_11_29_23\NETTesting.gdb\Patches‍‍

It errors out on this line:

result = arcpy.GetCount_management(svyPtFC)‍‍‍

As a result, I get this displayed on my webpage (and you can clearly see it has the correct path the feature class displayed):

Traceback (most recent call last):


File "C:\Users\xxx\xxx\PythonProjects\HabitatClassification.py", line 300, in <module>


result = arcpy.GetCount_management(svyPtFC)


File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 17419, in GetCount


raise e


ExecuteError: Failed to execute. Parameters are not valid.


ERROR 000732: Input Rows: Dataset C:\Users\xxx\Desktop\GIS_NET_Testing\ArcObjectsTesting\ArcObjects\UploadedFiles\NETTesting.gdb_02_17_2018_11_29_23\NETTesting.gdb\Patches does not exist or is not supported


Failed to execute (GetCount).








Failed to execute (HabitatClassification).
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Anybody know what's going on here? My first thought was the periods in the file path were causing an issue, but in the python IDE it goes through just fine so I'm not sure that's it.

0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

In the python script and environment variable is set so it knows where the data reside.

In the other incarnation, I don't recognize an equivalency.

You will have to check that both see the actual data files by either supplying them the complete paths directly or setting an environment parameter.

As for flotsam in file paths... spaces, periods are an issues in many situations.  As a test, try moving everything to a simple local folder and retry to rule out path constructs since python and your arcobjects may not see things the same.

0 Kudos