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.

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Apr 18, 2012 at 15:10
2
  • Is there a way to use a variable as 'current' with the mxd path in it? 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? 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')
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Apr 18, 2012 at 19:40
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.

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Apr 18, 2012 at 22:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.