Select to view content in your preferred language

Create blank MXD from python?

14655
11
Jump to solution
03-26-2010 02:46 PM
AndrewRudin
Deactivated User
I was looking through the new ArcPy functions, and I didn't see a function or Toolbox tool to just create a new blank MXD from scratch.  Does something like this exist?  Seems like a great function to have as a starting point for map manipulation.
11 Replies
DanielSmith
Frequent Contributor

old thread but i thought  i would post my answer as it does not require an existing map doc

this does assume that you have arcMap installed and not just arcpy. but who is using arcpy w/o having ArcMap installed?

{

map_file = r'c:\test\test_map..mxd'

# open and close a file

open(map_file,'r').close()

# open the file with default application

os.startfile(map_file)

# sleep for a couple minutes to allow the file to be fully opened

time.sleep(120)

# kill the application in a pretty violent way yet not corrupting the file.

os.system("taskkill /im arcmap.exe /f")

# work with yout map

mxd = arcpy.mapping.MapDocument(map_file)

}

0 Kudos
EnvironmentalIntelligence
Occasional Contributor

Old thread, but I just used your code although I had to change 'r' to 'w+' in third line. Is this due to changes in python since 2014? I don't understand how your code could work because with the open function in 'read' mode it could not create the file.

0 Kudos