Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use arcpy to save an .mxd and am having an issue. It doesn't matter if I use 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 == "contourLabelText":
        lyr.showLabels = True
    if == "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\", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\MGIS\geog485\FinalProject2\", line 7, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\", 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. It's really holding me up. I'm using ArcInfo 10.0 SP4.

Thanks in advance.

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
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 '12 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 '12 at 17:42 are correct. You cannot overwrite a mxd. I had to define 2 separate for the original mxd and another to save the layers I added to it. – niklas24 Apr 10 '12 at 22:52
@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 '13 at 18:48

The answer is:

You cannot overwrite a 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 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 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.

share|improve this answer

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 =
    mxd.title =
    mxd.saveACopy(r"C:\Project\Output\\" + + ".mxd")
del mxd

Note, this is also debugged extensively here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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