Thursday, February 14, 2013

Creating an Map Document From Python (10.1)

Previous posts, I have discussed ways to create map service layers from scratch, and now I'm going to show you how to create a blank map document using the 'ConvertWebMapToMapDocument' tool in ArcToolbox.  The beauty of this tool is that it doesn't have to be run on server, but can be run from desktop.  It uses JSON based on the ExportWebMap specification.

A JSON map consists of the following:
   "mapOptions": {}, 
   "operationalLayers": [], 
   "baseMap": [], 
   "exportOptions": {}, 
   "layoutOptions": {} 

import json
from arcpy import mapping
mapService = {} 
jsonDump = json.dumps(mapService) 
result = mapping.ConvertWebMapToMapDocument(jsonDump)
mxd = result.mapDocument

Now you can do whatever you need to do with your map document.