Select to view content in your preferred language

Open MXD File

8037
15
Jump to solution
04-18-2016 07:53 AM
ChrisHolmes
Frequent Contributor

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

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?

View solution in original post

15 Replies
DanPatterson_Retired
MVP Emeritus

usually referred to a "Current"

MapDocument—Help | ArcGIS for Desktop

RebeccaStrauch__GISP
MVP Emeritus

Dan...link is bad (geonet issue?)

I think Chris is wanting a new/different mxd in same session, not the CURRENT mxd.

0 Kudos
ChrisHolmes
Frequent Contributor

Yes, you’re correct Rebecca. Thanks!

0 Kudos
DanPatterson_Retired
MVP Emeritus

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?

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

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.

ChrisHolmes
Frequent Contributor

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!

0 Kudos
ChrisHolmes
Frequent Contributor

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

0 Kudos
curtvprice
MVP Esteemed Contributor

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?