3

I have a geoprocessing service that was successfully published to our Server instance. I'm using 10.3 which means we could not publish unless it was successfully run as a tool in ArcMap. But now when I try calling the GP service form my client I am getting an error that the dataframe object was not created properly. I am not sure why the script works in ArcMap and not on the server. Here is the script

import sys, string, arcpy, os

# get default script location
scriptPath = sys.path[0]

# Construct paths to mxd
mxdFilePath = os.path.join(scriptPath,"Mymxd.mxd")
mxd = arcpy.mapping.MapDocument(mxdFilePath)
df = arcpy.mapping.ListDataFrames(mxd)[0]
shpPath = arcpy.GetParameterAsText(0)
newLayer = arcpy.mapping.Layer(shpPath)
arcpy.mapping.AddLayer(df,newLayer,"TOP")
arcpy.RefreshActiveView()
del newLayer
del mxd

And here is the error

esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeInformative: Executing (MyService): MyService "Feature Set" C:\Users\~\AppData\Local\Temp\MyService\MyService_122215_1630_gpserver\j25ae6595a46840369acebfbd9d3fd12f\scratch\Printout1.pdf
esriJobMessageTypeInformative: Start Time: Tue Dec 22 16:55:18 2015
esriJobMessageTypeInformative: Executing (MyService): MyService "Feature Set" C:\Users\~\AppData\Local\Temp\MyService\MyService_122215_1630_gpserver\j25ae6595a46840369acebfbd9d3fd12f\scratch\Printout1.pdf
esriJobMessageTypeInformative: Start Time: Tue Dec 22 16:55:18 2015
esriJobMessageTypeInformative: Running script MyService...
esriJobMessageTypeInformative: Success reading the mxd from \\myserver\myshare\arcgisserver\directories\arcgissystem\arcgisinput\MyService\MyService_122215_1630.GPServer\extracted\v101\folder\MyService.mxd
esriJobMessageTypeError: Traceback (most recent call last): File "\\myserver\myshare\arcgisserver\directories\arcgissystem\arcgisinput\MyService\MyService_122215_1630.GPServer\extracted\v101\folder\GeoprocessingService_Test.py", line 20, in df = arcpy.mapping.ListDataFrames(mxd)[0] File "e:\arcgis\server\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "e:\arcgis\server\arcpy\arcpy\mapping.py", line 1479, in ListDataFrames result = mixins.MapDocumentMixin(map_document).listDataFrames(wildcard) File "e:\arcgis\server\arcpy\arcpy\arcobjects\mixins.py", line 728, in listDataFrames return list(reversed(list(self.dataFrames))) File "e:\arcgis\server\arcpy\arcpy\arcobjects\mixins.py", line 695, in dataFrames return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames) AttributeError: 'NoneType' object has no attribute 'dataFrames'
esriJobMessageTypeError: Failed to execute (MyService).
esriJobMessageTypeInformative: Failed at Tue Dec 22 16:55:19 2015 (Elapsed Time: 1.00 seconds)
esriJobMessageTypeError: Failed to execute (MyService).
esriJobMessageTypeInformative: Failed at Tue Dec 22 16:55:19 2015 (Elapsed Time: 1.00 seconds)
esriJobMessageTypeError: Failed.
  • Within the messages it says where it's trying to find the MXD. Does the MXD exist at that location? If you built your original task with the MXD relative to the script and allowed the publishing process to copy the MXD everything should just work. Sys.path is fine with a gp service just as long as the original setup was all relative – KHibma Dec 23 '15 at 21:55
1

Sys.path is going to point to a different location when running in the context of an arcgis server GP service vs the context of arcmap. There is no guarantee that sys.path[0] will be the same in arcmap and server.

Edit: Seeing arcpy.refreshActiveView in a script designed for a GP service is a red flag. That function only works on the current map document open in arcmap. I don't know what it's behavior is in a GP service. One quick sanity check is to try running the script without any open map document in Arcmap and see if you get a similar error.

EDIT: Even though the error is pointing to

df = arcpy.mapping.ListDataFrames(mxd)[0]

it's likely that this line:

mxd = arcpy.mapping.MapDocument(mxdFilePath)

is returning a bad mxd or the mxdFilePath is wrong or not accessible to arcgis server.

try running another method on the mxd to see if it's really the data frame or if it's a problem with the mxd itself.

mxd = arcpy.mapping.MapDocument(mxdFilePath)
arcpy.AddMessage('mxd opening from ' + mxd.filePath)
arcpy.mapping.ExportToPNG(mxd, r'c:\some_location_you_have_access_to')
  • Thank you for the suggestions. I removed the refreshActiveView since the arcpy.mapping export will export to the correct location. The sys.path will be different but that is fine since I am just using it to find the mxd. – Liz L. Dec 23 '15 at 18:04
  • I think the issue is with the parameters I am passing in – Liz L. Dec 23 '15 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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