I'm trying to use arcpy to save an .mxd and am having an issue. It doesn't matter if I use mxd.save or mxd.saveACopy I get the same error. I know it doesn't look like I am doing anything w/ it here, but it's just a portion of my code:

import arcpy
import arcpy.mapping as map
arcpy.env.overwriteOutput = True

env.workspace = r"C:\MGIS\FinalProject2.gdb    
mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")
df = map.ListDataFrames(mxd)[0]

for df in map.ListDataFrames(mxd):
df.scale = 2000000

#Add layers into map document
addLayer = map.Layer(OKXcounties)
addLayer1 = map.Layer(contourLabelText)
addLayer2 = map.Layer(contoursClipLyr)
addLayer3 = map.Layer(clipOKXLyr)
map.AddLayer(df, addLayer, "AUTO_ARRANGE")
map.AddLayer(df, addLayer1, "AUTO_ARRANGE")
map.AddLayer(df, addLayer2, "AUTO_ARRANGE")
map.AddLayer(df, addLayer3, "AUTO_ARRANGE")

# Add contour Labels
for lyr in map.ListLayers(mxd):
    if lyr.name == "contourLabelText":
        lyr.showLabels = True
    if lyr.name == "Contour Features":
        lyr.transparency = 100


I get the following error:

Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\MGIS\geog485\FinalProject2\mxdtest.py", line 7, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, in saveACopy
AttributeError: MapDocObject: Unable to save.  Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.

Space is not the issue, I have 60 GB of free space and I've checked the windows properties of the .mxd file. Read-only box is unchecked and I've "allowed" all permissions for all groups:


Does anyone have any idea how if this is a bug or how I can fix this?

I'm using ArcInfo 10.0 SP4.

3 Answers 3


In your code sample, you're trying to save the mxd object, not a path to the object.

i.e., mxd.saveACopy(mxd). This is not the correct way to perform this action.

The documentation advises using the entire file path, like the following:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for df in arcpy.mapping.ListDataFrames(mxd):
    mxd.activeView = df.name
    mxd.title = df.name
    mxd.saveACopy(r"C:\Project\Output\\" + df.name + ".mxd")
del mxd

Note, this is also debugged extensively here.


You cannot overwrite an mxd file that is already in use.

Therefore, if you access an mxd such as using:

mxd = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")

It becomes in use... via your python file. You are then able to use mxd.save() without any issues.

The issue arises if you have more than 1 python script accessing the same mxd file. (Only the 1st one that accessed it will be able to save)

Or you have opened the same mxd 2x inside a script without calling mxd.close()=.

mxd1 = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")
mxd2 = map.MapDocument(r"C:\MGIS\Finalproject2.mxd")

Or more likely, you have opened the mxd file inside ArcGIS desktop, so the file is in use there. Close ArcGIS desktop and the script will complete just fine.


My guess is that you cannot save "over" a file. Does it work if there is no file of that name already on disk? Try deleting the existing file before the save.

  • I guess I should have included that I have an env.workspace set and that I also have the overwrite = True (edited in original post), but the mxd falls outside of the .gdb so the overwrite doesn't apply to it. Is there a way to set the overwrite = true for files outside of the env.workspace setting?
    – niklas24
    Apr 9, 2012 at 17:30
  • I saved all of the code that uses the mxd variable so I need it to be defined and exist in order for it to work. There are variables included in my code above that aren't defined here, but are irrelevant to my mxd save issue. This is why I cannot remove the mxd file.
    – niklas24
    Apr 9, 2012 at 17:42
  • Chaz...you are correct. You cannot overwrite a mxd. I had to define 2 separate variables...one for the original mxd and another to save the layers I added to it.
    – niklas24
    Apr 10, 2012 at 22:52
  • 2
    @niklas24 - I know this is from a while back, but I am encountering the same problem your describe well here. Would you mind explaining in a little more detail how you fixed it? I'm not sure what you meant here re: defining 2 separate variables. Thank you!
    – SharonB
    Jul 29, 2013 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.