Hello everyone,
I am using this line of code to open up an mxd file:
os.startfile("c:/chris/{0}/{0} - existing_proposed.mxd".format(string))
It works and opens the file, but it opens in a new instance of ArcMap. Is there a way to have it open in the instance that is already open?
Thanks,
Chris
Solved! Go to Solution.
ArcPy itself lives within the current single-document interface thread of ArcMap so you can't directly do this without going to ArcObjects to interact with the process. The easiest way to do this is probably VBA. (I'm assuming you don't want to dive into .NET)
Opening up an MXD into the current ArcMap session using ArcPy?
usually referred to a "Current"
Dan...link is bad (geonet issue?)
I think Chris is wanting a new/different mxd in same session, not the CURRENT mxd.
Yes, you’re correct Rebecca. Thanks!
link is bad... grief. every time you run that code, you get a new instance, the arcpy.mapping mapdocument references are working with an already open map document which has been specified or is active before code is run. So... what is you want to do? open more instances or work with an already open instance?
Chris, can you explain why you are needing this? Are you trying to automate a task and need to interact with it manually, but you are just trying to speed up the open map proces?
if automating tasks with Python, thru a bunch of mxds, there are better ways to do it..no need to open each one physically.
I have a modelbuilder model which copies a number of mxd files to a new folder based on a index number that the user enters. The index is used for the name of the new folder and is also appended to the front of each mxd file.
Once the files are copied I want to open one of them which is what the os.startfile accomplishes. I just think it would be nicer if it opens in the instance that is already open.
If there is a better way to do this, please let me know. Thanks!
Hi Rebecca,
When you have a moment could you elaborate a bit on your comment, "there are better ways to do it..no need to open each one physically".
Thanks,
Chris
ArcPy itself lives within the current single-document interface thread of ArcMap so you can't directly do this without going to ArcObjects to interact with the process. The easiest way to do this is probably VBA. (I'm assuming you don't want to dive into .NET)
Opening up an MXD into the current ArcMap session using ArcPy?
You need ArcObjects.
Don't fret All is not lost...
How do I access ArcObjects from Python? - Geographic Information Systems Stack Exchange
Arcobjects in Python script tool to suppress the Save dialog