This isn't really a standalone answer, more of an addition to @PolyGeo's answer as it addresses the 'mxd creation from scratch' in python issue.
Note: it's probably a bit advanced for a python 'new bee'...
You can create MXD's from scratch in python if you access ArcObjects. You will need the comtypes package and if using ArcGIS 10.1, you need to make a small change to automation.py. See ArcObjects + comtypes at 10.1
Below is some code to create an MXD from scratch in python:
import comtypes,os
def CreateMXD(path):
GetModule('esriCarto.olb')
import comtypes.gen.esriCarto as esriCarto
pMapDocument = CreateObject(esriCarto.MapDocument, esriCarto.IMapDocument)
pMapDocument.New(path)
pMapDocument.Save() #probably not required...
def GetLibPath():
""" Get the ArcObjects library path
It would be nice to just load the module directly instead of needing the path,
they are registered after all... But I just don't know enough about COM to do this
"""
import _winreg
#Little kludge for 64bit OS
if 'PROGRAMFILES(X86)' in os.environ:path='SOFTWARE\\Wow6432Node\\ESRI'
else:path='SOFTWARE\\ESRI'
keyESRI = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path)
#Little kludge juuust in case ArcGIS 10.1 uses a different registry key,
#i.e. "Desktop10.1"...
nkeys=_winreg.QueryInfoKey(keyESRI)[0]
for i in range(nkeys):
subkey=_winreg.EnumKey(keyESRI,i)
if subkey[:7].lower()=='desktop' or subkey.lower()=='arcgis':
try:
keyDesktop = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path+'\\'+subkey)
compath=os.path.join(_winreg.QueryValueEx(keyDesktop,"InstallDir")[0],'com')
if os.path.exists(compath):return compath
except:pass
def GetModule(sModuleName):
""" Generate (if not already done) wrappers for COM modules
"""
from comtypes.client import GetModule
sLibPath = GetLibPath()
GetModule(os.path.join(sLibPath,sModuleName))
def CreateObject(COMClass, COMInterface):
""" Creates a new comtypes POINTER object where
COMClass is the class to be instantiated,
COMInterface is the interface to be assigned
"""
ptr = comtypes.client.CreateObject(COMClass, interface=COMInterface)
return ptr
if __name__=='__main__':
#testing...
import arcpy
arcpy.SetProduct('arcview')
filepath='c:/temp/testing123.mxd'
if os.path.exists(filepath):os.unlink(filepath)
CreateMXD(filepath)