Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Key_concepts_for_geoprocessing_services/002v00000002000000/

I'm trying to have a new GP Service arcpy.AddMessage() the scratchworkspace that is created on that run. I keep getting a invalid syntax error.

But real aim is to write to this scratchworkspace but the %scratchworkspace%/ doesn't seem to be working for me.

line = arcpy.GetParameterAsText(0)
arcpy.AddMessage(line)
try:
    arcpy.AddMessage(str(%scratchworkspace%))
except:
    arcpy.AddMessage(traceback.format_exc())

This is a gp service published through the arcmap process, I've opened and run the tool layer once already and the Tool is creating the scratchworkspace in arcgisjobs directory

arcgisjobs\geoprocessing\gpservicetest_gpserver\jf93e76ce2f0f4967b7b9028c384b19f8\scratch

So how do I get a hold of this in python to write to?

Thanks.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Combing through this guys code (thanks for the link on the other question!) Setting Output Parameter in ArcPy for Server Tool

yielded this and it WORKED!

"%SCRATCHWORKSPACE%\\outPoint.shp"

as an output parameter to a arcpy.CopyFeatures_management call.

share|improve this answer
add comment

%scratchworkspace% is not resolved by the Python script. Instead it is set when passed as a tool input through ArcGIS Desktop or Server.

I.E. if you have a tool parameter, say scratch_dir and set it to %scratchworkspace% within the ArcGIS environment before you run the tool, accessing scratch_dir would give you the directory path (e.g. arcgisjobs\etc...).

So, modifying your code above:

line = arcpy.GetParameterAsText(0)
arcpy.AddMessage(line)
scratch_dir = arcpy.GetParameterAsText(1)
try:
    arcpy.env.workspace = scratch_dir
except:
    arcpy.AddMessage(traceback.format_exc())
share|improve this answer
add comment

I think you will need to use arcpy.env.scratchWorkspace instead of %scratchworkspace%.

This blog posting makes mention of %scratchworkspace% only being applicable to ModelBuilder and this Help page provides more details about arcpy.env.scratchWorkspace.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.