I have an eventual GP service that takes an MXD, alters it based on user input, and then exports it to a PDF to return to the user. I know when the MXDs get published to the server, they'll be located in this folder:
C:\arcgisserver\directories\arcgissystem\arcgisinput\PrintService\Print.MapServer\extracted\v101\MyFile.mxd
In the script, how should I reference where those MXDs are? I don't think it's best practice to hardcode something like that, is it? If I were to use the below script, would the path "D:\GIS_Testing\...." be replaced with an ESRI variable once it's published to Server? I'm just not sure how to define it so it can find the MXDs once it's up on my server.
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'D:\GIS_Testing\HabitatDbase\PrintTesting'</SPAN>
<SPAN class="comment token">#Get the map document to manipulate based on whether the user wants a portrait or a landscape layout map</SPAN>
<SPAN class="keyword token">if</SPAN> orientation <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Portrait"</SPAN><SPAN class="punctuation token">:</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'PortraitLayout.mxd'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'LandscapeLayout.mxd'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
For what it's worth, I write the output file to scratchFolder, which I believe is fine:
outputPDF <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ExportToPDF<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Map.pdf"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">7</SPAN><SPAN class="punctuation token">,</SPAN> outputPDF<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>