Opening up an MXD into the current ArcMap session using ArcPy?

10934
8
01-12-2011 02:42 PM
EricAubert
New Contributor II
I�??m converting  a mapping system into ArcPy.  I�??ve made great progress but hit a stumbling block!!!  I want my users to be able to pick, from a pick list, a pre-made mxd and load it into their current ArcMap session.  I�??ve created this simple toolbox but�?� could not find any ArcPy method for loading an mxd into the current session? 

I could load layer files instead but that would defeat my purpose since the mxds have several elements in the layout (header, footer, north arrow, tailored legend, etc.) that I want to preserve .  Since we can�??t create these elements in ArcPy, I am kind of stuck!  Using ArcObject to do such a simple task would be kind of ridiculous too.  Am I missing something here or was it an oversight in ArcPy?

I can open up an mxd into a �??separate�?� session though, but that�??s not want I�??m trying to achieve:
mxd = r"C:\Temp\eaub490\SUMA\Products\Timber Sales Map\Timber Sales Map.mxd"
os.startfile(mxd)

Any helps or comments would be greatly appreciated.

Eric
0 Kudos
8 Replies
JeffBarrette
Esri Regular Contributor
Eric,

Arcpy.mapping was designed for automating map documents (mxds) and layer files (lyrs), not the ArcMap application.

The functionality you are requesting is crossing into the realm of desktop customization and that is what ArcObjects is for.

Jeff
0 Kudos
EricAubert
New Contributor II
Thanks Jeff for your response.  I still believe that being able to open up an mxd into the current (active) session is not crossing too far into the "realm of desktop customization", it would open up so many possibilities.  Let's put it that way, would it be nice to have a method like this one: 

arcpy.mapping.MapDocumentOpen(mxd_path)

Ok, I'll stop pushing your button 🙂

Eric
0 Kudos
DanielVoisey
New Contributor
I had the same problem - try this:

import os
os.startfile(path to mxd)

Cheers

Danny
ChrisBates1
New Contributor
Wow I know that this topic was written a long time ago - but I am looking for a solution to the exact same thing.

I have a blank mxd saved on my network and I add a bunch of layers to it.
I really want to simply open that document once the layers have been added and "see" them in the TOC.

arcpy.mapping does not ever seem to refresh the TOC (even using arcpy.RefreshTOC()) unless I save the mxd arcpy.mapping.MapDocument.saveACopy() and open the new one.

What I want is to dump all of the layers into a 'read-only' MXD open the mxd, and BAM! there are my layers. and then it is up to the user to decide if they want to save it or not.

I've tried accomplishing this with os.startfile(). But the os module doesn't seem to wait for the arcpy objects etc to do their thing before opening the MXD.

Even if the MXD is open and I load the layers I can't "see" them unless I save. It's absolutely bogus!

Any solutions?

Chris
0 Kudos
LinkElmore
New Contributor III
Just finding this thread as well after attempting to do the same task.  I just wanted to note that the os.startfile("/path") method works but does so by opening up a new instance of ArcMap.  This is not the same as changing the CURRENT map document to the new one.  Of course, I'm typing into the Python window within ArcMap rather than executing as a standalone script, which I haven't tried.
0 Kudos
JeffBarrette
Esri Regular Contributor
Redirecting the active MXD app is not possible with arcpy.mapping.  It was not designed to do this.  Its purpose was to connect to existing, pre-authored MXDs.  For similar reasons, you can't change page size, orientation, etc.

Jeff
0 Kudos
ChristopherRobertson
New Contributor II
I know I am bumping a really old thread but I want to do this with ArcObjects in C#.NET cant find a whole lot on opening it in the active session. Anyone have a code snippet handy for doing this within the onClick() event of a button.
0 Kudos
JasonScheirer
Occasional Contributor III
0 Kudos