I'm creating a script that will convert all of my MXDs to APRXs, and I find it extremely inconvenient that I can't create a new blank project from scratch form within ArcGIS Pro. This utility would make switching to ArcGIS Pro so much easier, along with the ability to create blank toolboxes.
Edited to add: @Rhys-Donoghue posted a good workaround for this issue if anyone is interested.
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Users\Graeme\AppData\Roaming\ESRI\Desktop10.1\ArcMap\Templates\Normal.mxt")
mxd.saveACopy(r"C:\temp\test.mxd")
sources:
pip - Installing python module within code - Stack Overflow
python:
import arcpy
import subprocess
import sys
def install(package):
subprocess.call([sys.executable, "-m", "pip", "install", package])
install('comtypes')
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
"""
compath=os.path.join(arcpy.GetInstallInfo()['InstallDir'],'com')
return compath
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...
arcpy.SetProduct('arcview')
filepath='c:/admin/testing123.mxd'
if os.path.exists(filepath):os.unlink(filepath)
CreateMXD(filepath)
We can NOT implement this idea with arcpy/arcpy.mp. Creating a new project requires a "restart" and because Python gets loaded after the project is being opened, its a bit of a catch-22. For a similar reason, there are some project options that can't be changed using arcpy.mp because the project needs to be restarted after a change is made.
Jeff - arcpy.mp and Layout teams.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.