AnsweredAssumed Answered

how to access map document layers in a python script tool?

Question asked by on Feb 7, 2012
Latest reply on May 2, 2012 by simo
I've got a script tool that works in ArcGIS 10 Desktop.

I want to publish it to ArcGIS Server.

The tool needs access to layers. So I placed the tool as a 'tool layer' in a 'source map document', and published the map document as a geoprocessing service. I was trying to follow the advice of the ArcGIS Help that suggested that doing so, rather than publishing the toolbox itself, will prevent my tool from having to spool up expensive connections with each execution.

In the Python script, I use
to get the current map document, so I can get its layers.

I get this error when I try to run the task from the server: Object: CreateObject cannot open map document Failed to execute.

I've seen reference to that error when trying to use arcpy.mapping.MapDocument("CURRENT") if a script tool doesn't have its 'always run in foreground' box checked. It does. See

Makes me wonder if server tasks run in the background anyway, and arcpy.mapping.MapDocument("CURRENT") can't work in a script used as a server geoprocessing task. 

Then how does my script get layers from the tool layer's source map document?