2

I am wondering if it is possible to build a zoom to geoprocessing service without using 'current' for the MXD variable in Python? Using 'current' my tool works in ArcMap, but not in my geoprocessing service.

Here is my code that work fine locally in ArcMap:

import arcpy


MXD=arcpy.mapping.MapDocument('current')    
dataframe = arcpy.mapping.ListDataFrames(MXD, "Web Mercator")[0]   
dataframe.zoomToSelectedFeatures() 
arcpy.RefreshActiveView() 

When I publish my service, the zoom feature no longer works. I have read online that you can't use 'current' in a geoprocessing service, that's fine. When I enter the path to the MXD, the zoom function no longer works.

2
  • Is there a way to use a variable as 'current' with the mxd path in it?
    – Emily
    Commented Apr 18, 2012 at 16:12
  • I don't know much about GP services, but since it is server side, not client side, doesn't that mean it is unable to affect/interact with the current map document/active view?
    – blah238
    Commented Apr 18, 2012 at 23:20

2 Answers 2

2

I think you need to set the path to your map - CURRENT only works if you're in ArcMap.

MXD=arcpy.mapping.MapDocument(r'C:\data\new.mxd')
2

From the code supplied in the question it is not possible to see how you can tell that the zoom is not working when you specify the mxd (which is the way I do this) rather than CURRENT.

Perhaps include an MXD.save(), MXD.SaveACopy(...), or an arcpy.mapping.ExportToPDF(...) to "trap" the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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