[GIS] AttributeError: MapDocObject: Unable to save on mxd.save/saveACopy

arcgis-10.0arcpyattributeerrormxd

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

mxd.saveACopy(mxd)

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>
    mxd.saveACopy(mxd)
  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
    self._arc_object.saveACopy(file_name)
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:

mxdproperties

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

I'm using ArcInfo 10.0 SP4.

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

Note, this is also debugged extensively here.

Related Question