<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to access map document layers in a python script tool? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238200#M8129</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Mark,&lt;BR /&gt;&lt;BR /&gt;You cant access "CURRENT" within a GP Service. You're correct, its the same idea as background processing. You'd have to set explicit paths to the map document you want to build your GP Service for arcpy.Mapping around.&lt;BR /&gt;From your post the other day - what is your end goal? &lt;BR /&gt;--To use layers inside tools within your service (the use of layers to save the re-open cost on execution)&lt;BR /&gt;or&lt;BR /&gt;--To interact with layers, and map documents with the end goal of creating a jpeg or pdf which could be printed&lt;BR /&gt;&lt;BR /&gt;While these ideas both use "layers", technically they go about it differently. Yes, all things equal they're all layers, but when it comes down to it:&lt;BR /&gt;arcpy.Mapping.Layer (&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/&lt;/A&gt;) does not equal "layers" you use in a tool (&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;If you goal is to use layers in a service for tool execution, your workflow is basically:&lt;BR /&gt;&lt;BR /&gt;-Add the layers you want to use into your map document&lt;BR /&gt;-Create your script. Where your tool executes against a "layer", simple use a string inside the tool parameter with the layers name.&lt;BR /&gt;--Its this 1:1 match up of the layers name in the ToC and the string inside your script which makes this work&lt;BR /&gt;-Create a tool layer. (drag the tool into the ToC).&lt;BR /&gt;-Publish using "Add New Service" - look for the topic title &lt;STRONG&gt;"Geoprocessing service with a source map document"&lt;/STRONG&gt; located at: &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the second end goal: manipulate the layers and using the source map document to generate a pdf.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of accessing the layers, I want to access the map document itself, and need to export a pdf file using the map document. currently, I open mxd file in the python script by something like the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it's veeeery slow. I reckon the cost of opening the mxd if quite high, as I have a heavy mxd with tens of layers. so, naturally I think it will be handy just keep the map document open once the GP service starts, and just reference the map document like the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know it's not gonna working, because CURRENT only works for ArcMap and foreground execution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, I am really scratching my head: is there a shortcut to the reference of the map document in the server memory? is there a map document in the memory if I publish a GP service using a toollayer in the related map document? if not, why I can access layers in the map document by name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or comments are highly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 May 2012 11:54:12 GMT</pubDate>
    <dc:creator>simoxu</dc:creator>
    <dc:date>2012-05-02T11:54:12Z</dc:date>
    <item>
      <title>how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238194#M8123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've got a script tool that works in ArcGIS 10 Desktop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to publish it to ArcGIS Server.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the Python script, I use &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;arcpy.mapping.MapDocument("CURRENT")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt; to get the current map document, so I can get its layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get this error when I try to run the task from the server: &lt;/SPAN&gt;&lt;STRONG&gt;Object: CreateObject cannot open map document Failed to execute&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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 &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001500000021000000.htm" rel="nofollow" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001500000021000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then how does my script get layers from the tool layer's source map document?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 21:39:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238194#M8123</guid>
      <dc:creator>markcheyne</dc:creator>
      <dc:date>2012-02-07T21:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238195#M8124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Mark,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You cant access "CURRENT" within a GP Service. You're correct, its the same idea as background processing. You'd have to set explicit paths to the map document you want to build your GP Service for arcpy.Mapping around.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;From your post the other day - what is your end goal? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--To use layers inside tools within your service (the use of layers to save the re-open cost on execution)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--To interact with layers, and map documents with the end goal of creating a jpeg or pdf which could be printed&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While these ideas both use "layers", technically they go about it differently. Yes, all things equal they're all layers, but when it comes down to it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Mapping.Layer (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/&lt;/A&gt;&lt;SPAN&gt;) does not equal "layers" you use in a tool (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you goal is to use layers in a service for tool execution, your workflow is basically:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Add the layers you want to use into your map document&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Create your script. Where your tool executes against a "layer", simple use a string inside the tool parameter with the layers name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--Its this 1:1 match up of the layers name in the ToC and the string inside your script which makes this work&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Create a tool layer. (drag the tool into the ToC).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Publish using "Add New Service" - look for the topic title &lt;/SPAN&gt;&lt;STRONG&gt;"Geoprocessing service with a source map document"&lt;/STRONG&gt;&lt;SPAN&gt; located at: &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Feb 2012 22:20:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238195#M8124</guid>
      <dc:creator>KevinHibma</dc:creator>
      <dc:date>2012-02-07T22:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238196#M8125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hi kevin, i really appreciate your reply. a little more elaboration/clarification?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;yes, my goal is to avoid having to, with each execution of my script, expend the processing time to create a new connection to a layer on which to do the geoprocessing task's work. In other words, avoid this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management("..mygdb/mydataset/myfeatureclass", outlayer)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;where outlayer becomes an instance of arcpy.mapping.layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I thought that publishing a geoprocessing service based on a map document with a tool layer would keep the map document's layers in memory, and&amp;nbsp; I could grab them from the map document's arcpy.mapping layers collection after I got hold of the current document with 'CURRENT'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But you've confirmed I can't use 'CURRENT' in a server-based script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I read your reply to mean this - I can get a given layer, for purposes of passing it as an input to a tool that normally requires a layer as input, by passing the name of the layer to that tool. Like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.Buffer_analysis('layer name in source map doc TOC', '%scratchworkspace%\out.shp', '100 Miles')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do I have that right?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;But what I want is this&lt;/STRONG&gt;&lt;SPAN&gt; - the code of my script wants to actually use the layer object, not pass it as input to another tool. Specifically in my case, I want my script to loop over the selected rows in the layer in a for loop. So again, how do I get hold of an actual arcpy.mapping.layer instance? Maybe I read your reply to mean:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeFeatureLayer_management("layer name in source map doc TOC", outlayer)
rows = arcpy.SearchCursor(outlayer)
&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; do stuff with the row
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks again, MC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:00:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238196#M8125</guid>
      <dc:creator>markcheyne</dc:creator>
      <dc:date>2021-12-11T12:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238197#M8126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After a few days out of office, I tried the approach suggested in my last post above, without joy. If I try in Python code to get a layer object using the layer's name from the source map document TOC, I get the following error, using the tool on Desktop of after publishing the source map document as a geoprocessing service:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error executing tool.: &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000735: Input Feature Layer: Value is required&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByLocation).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd really appreciate any suggestions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, MC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2012 15:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238197#M8126</guid>
      <dc:creator>markcheyne</dc:creator>
      <dc:date>2012-02-10T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238198#M8127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm a doofus.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) tools that take a layer as input can also take a string instead (or a geometry object, another subject) - a path, or a TOC layer name in the case of a a tool running in an ArcMap document (Desktop) or a tool layer (Desktop or Server).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) any tool that produces an output parameter will expose it in script as part of a Result object. In my case that's where I needed to get my layer object from.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RTFM: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_tools_in_Python/002z0000000n000000/" rel="nofollow" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_tools_in_Python/002z0000000n000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;inpoint = arcpy.Point(arcpy.GetParameter(0), arcpy.GetParameter(1)) inpointgeo = arcpy.PointGeometry(inpoint) bufferradius = arcpy.GetParameter(2) result = arcpy.SelectLayerByLocation_management("TOC layer name", "WITHIN_A_DISTANCE", inpointgeo, bufferradius, "NEW_SELECTION") layer = result.getOutput(0) rows = arcpy.SearchCursor(layer) for row in rows: &amp;nbsp; do stuff with a row&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;D'oh!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks all, MC&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2012 18:01:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238198#M8127</guid>
      <dc:creator>markcheyne</dc:creator>
      <dc:date>2012-02-10T18:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238199#M8128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Glad you got it figured out - I had just created a little script tool and map document to prove what you're trying to do, but came on and see you got it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Feb 2012 18:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238199#M8128</guid>
      <dc:creator>KevinHibma</dc:creator>
      <dc:date>2012-02-10T18:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to access map document layers in a python script tool?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238200#M8129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Mark,&lt;BR /&gt;&lt;BR /&gt;You cant access "CURRENT" within a GP Service. You're correct, its the same idea as background processing. You'd have to set explicit paths to the map document you want to build your GP Service for arcpy.Mapping around.&lt;BR /&gt;From your post the other day - what is your end goal? &lt;BR /&gt;--To use layers inside tools within your service (the use of layers to save the re-open cost on execution)&lt;BR /&gt;or&lt;BR /&gt;--To interact with layers, and map documents with the end goal of creating a jpeg or pdf which could be printed&lt;BR /&gt;&lt;BR /&gt;While these ideas both use "layers", technically they go about it differently. Yes, all things equal they're all layers, but when it comes down to it:&lt;BR /&gt;arcpy.Mapping.Layer (&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/&lt;/A&gt;) does not equal "layers" you use in a tool (&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000073000000&lt;/A&gt;)&lt;BR /&gt;&lt;BR /&gt;If you goal is to use layers in a service for tool execution, your workflow is basically:&lt;BR /&gt;&lt;BR /&gt;-Add the layers you want to use into your map document&lt;BR /&gt;-Create your script. Where your tool executes against a "layer", simple use a string inside the tool parameter with the layers name.&lt;BR /&gt;--Its this 1:1 match up of the layers name in the ToC and the string inside your script which makes this work&lt;BR /&gt;-Create a tool layer. (drag the tool into the ToC).&lt;BR /&gt;-Publish using "Add New Service" - look for the topic title &lt;STRONG&gt;"Geoprocessing service with a source map document"&lt;/STRONG&gt; located at: &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Publishing_geoprocessing_services/002v00000009000000/&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the second end goal: manipulate the layers and using the source map document to generate a pdf.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of accessing the layers, I want to access the map document itself, and need to export a pdf file using the map document. currently, I open mxd file in the python script by something like the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it's veeeery slow. I reckon the cost of opening the mxd if quite high, as I have a heavy mxd with tens of layers. so, naturally I think it will be handy just keep the map document open once the GP service starts, and just reference the map document like the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know it's not gonna working, because CURRENT only works for ArcMap and foreground execution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, I am really scratching my head: is there a shortcut to the reference of the map document in the server memory? is there a map document in the memory if I publish a GP service using a toollayer in the related map document? if not, why I can access layers in the map document by name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or comments are highly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 11:54:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-access-map-document-layers-in-a-python/m-p/238200#M8129</guid>
      <dc:creator>simoxu</dc:creator>
      <dc:date>2012-05-02T11:54:12Z</dc:date>
    </item>
  </channel>
</rss>

