Hello,
I have a script that creates a series of maps via a python script. After the script runs the automation (via a batch file), i want to put in a command to actually launch/open the MXD files. I know I have used this syntax in the past, but I can't seem to locate it. Does anyone know what command to use for open an mxd?
Hi Andrew,
As far as an arcpy option, I am not sure. But I just tried this script and it worked for me within the python window in arcmap.
import os
os.startfile("Path to your mxd")
I think it emulates a double click event and opens pretty much any file you give it as far as I have seen.
Thanks this is what I was looking for! However, now i am getting an error message saying "Coercing to Unicode: need string or buffer, Map document found." Any idea what this means?
That's a good question. Are you typing in the full path or giving it a variable with the path stored in it?
when I googled your error message I came across a similar stack exchange question here. I am by no means an expert with python but it looks like it might be expecting a string and instead getting a list or something.
AH! I just tried os.startfile() but replaced the variable in () with a hardcoded full path to another MXD and it worked fine! I might have to do some switching and play with the concatenation of a new variable due to the fact that my script automatically creates project folders and geodatabases unique to a project ID #. But this is a great start, thanks.
I try to use the r string prefix with path names so it escapes the backslashes.
mypath = r"C:\temp\myfile.mxd"
Or you can construct file paths with os.path
mydrive = "c:" myfolder = "temp" myfile = "mapdoc.mxd" mypath = os.path.join(mydrive, myfolder, myfile)
Yes, os.path.join is great, and here's just one more option:
mypath = r"C:\{0}\{1}.mxd".format(myfolder, myfilename)