Best practices for workspaces for GP Service

309
3
10-31-2018 11:12 AM
MollyFoley
Regular Contributor

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.env.workspace = r'D:\GIS_Testing\HabitatDbase\PrintTesting'

#Get the map document to manipulate based on whether the user wants a portrait or a landscape layout map
if orientation == "Portrait":
    mxd = arcpy.mapping.MapDocument(os.path.join(arcpy.env.workspace, 'PortraitLayout.mxd'))
else:
    mxd = arcpy.mapping.MapDocument(os.path.join(arcpy.env.workspace, 'LandscapeLayout.mxd'))

For what it's worth, I write the output file to scratchFolder, which I believe is fine:

outputPDF = arcpy.mapping.ExportToPDF(mxd, os.path.join(arcpy.env.scratchFolder, "Map.pdf"))
arcpy.SetParameterAsText(7, outputPDF)
Tags (1)
0 Kudos
3 Replies
JonathanQuinn
Esri Frequent Contributor

If the MXDs are in a registered location, the path should be kept the same. If they're not, then it should be packaged up with the service and extracted to the arcgisinput folder, as you pointed out. The path in the script will be updated as well, so no need to worry about that.

MollyFoley
Regular Contributor

Ok, probably a dumb question, but how would I package the two MXDs up with the GP service for publishing? Or do I just copy the MXDs and place them into the arcgisinput folder directly? 

I have tried registering the folder without success. I'm sure it has to do with permissions but I can't determine what's wrong with them. The publishing machine and the server machine are different. My ArcGIS Server Account is a domain account and that same domain account is an administrator on the publishing machine and has full control over the D: drive but for some reason it won't let me access the folder where the MXDs are kept (D:\GIS_Testing\PrintTesting\mapdoc.mxd). I have attempted moving that folder to the C:\Users drive but no luck there either.

0 Kudos
JonathanQuinn
Esri Frequent Contributor

I replied to your other thread but I'll reply here too.

If any data is in a non-registered location, the publishing process should package them and extract them in the arcgisinput location automatically. You don't need to do anything.

In terms of registering the data, you can either:

1) copy the MXDs, (approach above, requires you to republish if the original MXDs change)

2) Set up your PrintTesting folder as a share, register the share, and update your scripts

3) Copy the whole directory to the Server. You'll have two separate copies of the MXDs, and your machine will reference the copy on your machine and the Server will reference the copy on the Server machine. This is not too common when the machines can talk to each other. You typically use this approach when your machine is Windows and the Server is on Linux or you're using a deployment in the cloud.

0 Kudos