Select to view content in your preferred language

Geoprocessing Script Tool Fails - scratchWorkspace tool or environment not found

2773
1
Jump to solution
12-26-2012 11:02 AM
Jay_Gregory
Regular Contributor
I have a python script which when run in ArcMap works perfectly....
When creating the script tool in ArcMap, "Always run in foreground" is unchecked, "store relative path names" is checked, and "run python script in process" is checked. 
However, when I publish this script to an ArcGIS for Server 10.1 SP1 installation, executing the GPService fails with the following error from the logs:
Traceback (most recent call last):
  File "E:\arcgisserver\directories\arcgissystem\arcgisinput\EON\AirportsExportPython.GPServer\extracted\v101\toolboxes\AirportsExport.py", line 38, in <module>
    outputFclass = arcpy.env.scratchWorkspace+"\\clipped.shp"
  File "c:\program files\arcgis\server\arcpy\arcpy\geoprocessing\_base.py", line 525, in get_
    return self[env]
  File "c:\program files\arcgis\server\arcpy\arcpy\geoprocessing\_base.py", line 575, in __getitem__
    return convertArcObjectToPythonObject(getattr(self._gp, item))
AttributeError: Object: Tool or environment <scratchWorkspace> not found


Here is the script:
import arcpy, csv, os arcpy.env.overwriteOutput = True  # Script arguments Selecting_Geometry = arcpy.GetParameterAsText(0) if Selecting_Geometry == '#' or not Selecting_Geometry:     Selecting_Geometry = r"E:\EON\data\templates.gdb\polygonTemplate"   OutputType = arcpy.GetParameterAsText(1) if OutputType == '#' or not OutputType:     OutputType = "kmz"   # Local variables: arcpy.env.scratchWorkspace = r"E:\EON\temp" outputFclass = arcpy.env.scratchWorkspace+"\\clipped.shp" AirportsLayer = r"E:\EON\layers\LandingFacilitiesOrganized.lyr" Airports = r"E:\EON\data\FAA.gdb\airports" exportLayer = arcpy.env.scratchWorkspace+"\\exportLayer.lyr"  # Process: Clip arcpy.Clip_analysis(Airports, Selecting_Geometry, outputFclass, "") OutputFile = arcpy.env.scratchWorkspace+"\\airportsExportResult.kmz" earthLayer = arcpy.mapping.Layer(AirportsLayer) for layer in earthLayer:     if layer.isGroupLayer:         continue     else:         layer.replaceDataSource(arcpy.env.scratchWorkspace, "SHAPEFILE_WORKSPACE", "clipped") earthLayer.saveACopy(exportLayer) arcpy.LayerToKML_conversion(exportLayer, OutputFile, "1", "false", exportLayer, "1024", "96", "CLAMPED_TO_GROUND") arcpy.SetParameterAsText(2,OutputFile) 


In short, this script clips a feature set to an input polygon, applies a complicated layer file to it, then exports to kmz.  I got this geoprocessing tool working correctly earlier, but was using arcpy.env.workspace instead of arcpy.env.scratchWorkspace, so the process wasn't referencing the clipped file in a jobs directory, but instead in the hardcoded workspace directory in the script.  Anyway, after some research I saw that I have to use scratchWorkspace for all intermediate data.  But this broke the geoprocessing service.  Any assistance would be greatly appreciated!

Thanks, Jay
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Jay_Gregory
Regular Contributor
I spoke too soon - this was an easy fix by just not hardcoding the scratch workspace in the script!  It works now...

View solution in original post

0 Kudos
1 Reply
Jay_Gregory
Regular Contributor
I spoke too soon - this was an easy fix by just not hardcoding the scratch workspace in the script!  It works now...
0 Kudos