[GIS] Converting dwg to shapefile using arcpy and ArcGIS js

arcgis-javascript-apiarcpydwgerror-000732geoprocessing-service

The following code in arcpy is used to convert a dwg file into shapefile and it works perfectly when you run it within ArcMap:

import sys, zipfile, arcpy, os, traceback
from arcpy import env
# Set environment settings
env.workspace = "C:/GISApplication/GIS/Layer_Updated_Drawings"

# Set local variables
fileName = arcpy.GetParameterAsText(0)
featureType = arcpy.GetParameterAsText(1)
file = os.path.join(fileName, featureType)
inFeatures = [file]
outLocation = "C:/GISApplication/GIS/Layer_Updated_Drawings/Converted"

# Execute FeatureClassToGeodatabase
arcpy.FeatureClassToShapefile_conversion(inFeatures, outLocation)

However when I try to run this script using the following JavaScript code:

url = ARCGIS_SERVER + 'Toolbox/DwgToZippedShapefile/GPServer/LayerUpdate';
convParams = {
FileName: "MIPBoundary.dwg",  //Hardcoded for testing
FeatureType: "Polyline" //Hardcoded for testing
};
convExportToolName = "SHPFileResults";
convJobFolder = "DwgToZippedShapefile_GPServer";
var gpConversionProcess = new Geoprocessor(url);
gpConversionProcess.submitJob(convParams, gpConversionComplete, gpConversionStatus, gpConversionFailed);

it keeps failing and I keep getting the following error on arcgis server manager:

Error executing tool. LayerUpdate Job ID:
j7af4b50ca616491eb13dce08dfe17b7f : Traceback (most recent call last):
File
"(PATH)\Toolbox\DwgToZippedShapefile.GPServer\extracted\v101\my_toolboxes\UpdateLayer.py",
line 25, in arcpy.FeatureClassToShapefile_conversion(inFeatures,
outLocation) File "(PATH)arcgis\server\arcpy\arcpy\conversion.py",
line 2775, in FeatureClassToShapefile raise e ExecuteError: Failed to
execute. Parameters are not valid. ERROR 000732: Input Features:
Dataset Boundary.dwg\Polyline does not exist or is not supported
Failed to execute (FeatureClassToShapefile). Failed to execute
(LayerUpdate). Failed to execute (LayerUpdate).

However I don't know why it isn't working as I am passing all the parameters and when running the tool in ArcMap with the exact same parameters it works fine.

Best Answer

The problem, as Vince as inferred in the comments is the service does not know where the input data is.

So to go through the checklist:

  • works in arcmap, great
  • publishes without error, great
  • can consume the service back in arcmap, great
  • fails from JS client: indicates JS is not passing/telling the service the right details to run the service.

It looks like your input parameter is of type FILE (that is good), but JS is passing it this:

convParams = {
FileName: "MIPBoundary.dwg",  //Hardcoded for testing
FeatureType: "Polyline" //Hardcoded for testing
};

Essentially you're passing the service a string that the service has no idea what it is. The JS client needs to pass the actual DWG file onto the service. (That is why ArcMap works when consuming the service, it passes the file to the service for you). In short, you need to write more code to upload the DWG file. First you need to enable the uploads capability which is a service level setting. After that you need to write a little bit of JavaScript to upload the file. See the example in the File Upload service. (Note, this server is slated for retirement, so this link will go dead, but I'm absolutely certain I've put this upload JS code here in another GIS.SE post, I just cant find it)

Alternatively for testing, you can tell the service where the file is on a webserver and it'll go get it. Place your DWG file on a webserver somewhere and use the following at the REST end point (services directory) {'URL':'http://myserver/MIPBoundary.dwg'} (I'm not sure how you'd write this notation into your JS client)

Related Question