Select to view content in your preferred language

how to close "Current" Map Document?

3101
5
12-02-2010 07:44 AM
CosminTana
New Contributor
How can I close a map document via python?
I want to run a script which references the map document

mxd = arcpy.mapping.MapDocument("Current")
...
do_some_stuff()
....
mxd.saveACopy(r"C:\xx\yy\zz.mxd")
os.startfile(r"C:\xx\yy\zz.mxd")

and now i would like to close the "old" mxd???

The only thing I found to work is:
os._exit()

but this kind of kills ArcMap too brutal...
e.g. ArcSOCP.exe and ArcSOMP.exe won't close (for the next 10 min..)
is there anything like:
mxd.close()       ????
or a better closing method?

Sure, it is just one click to exit Arcmap. It is not extremely important, but nevertheless I would like to enforce closing the mapDocument in my script (in a proper way)...
0 Kudos
5 Replies
EricAubert
New Contributor II
Cosmin,

I'm assuming that you are running your script though the ArcPy window, am I correct? If so, why not using IDLE or PythonWin instead?  That way you would not need to open up an ArcMap session to do what you need to do, you would just refer to your map document object instead:

mxd = arcpy.mapping.MapDocument(<mxd path>)

Your issue description does not tell me why you need to "close" ArcMap.  If you could elaborate then I might be able to help.
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Application.shutdown
0 Kudos
CosminTana
New Contributor
I wrote my script in pythonwin and appended it to a toolbox...
For the future I want to make my script flexible. That means,
I want to be able to call it from ArcCatalog (the preferred method) but also from ArcMap.

If I call it from ArcMap, I want to close exactly that ArcMap session which called the script.
There is a reason for this, but back to the problem.

So far os._exit() is the only thing which works, but not optimal...
And
os.system('taskkill /IM Arcmap*')
would close the ArcMap session the correct way- but unfortunately it will close all open ArcMap sessions.

Application.shutdown <-- Couldn't find anything on this in combination with Python...
Can your write the correct syntax maybe?
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
hi,

Application.shutdown is vba code syntax...I dont know Python....


Thanks and Regards,

Venkat
0 Kudos
EricMahaffey
New Contributor III
Thanks Cosmin,

The os.system('taskkill /IM Arcmap*') was what I needed.
0 Kudos