[GIS] Zoom to selected feature, without using ‘current’ in ArcPy

arcpygeoprocessingpythonselect

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.

Best Answer

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')