Select to view content in your preferred language

saveACopy error "Unable to save"

2920
2
11-08-2013 02:14 PM
OliverSoong
Emerging Contributor
I've been using saveACopy in python and have been encountering strange errors as I develop my mapping/geoprocessing scripts.  To demonstrate the problem, I saved a blank mxd to C:/tmp/test.mxd.  It appears to be important to run the examples in fresh python sessions each time.  This code:

import arcpy
mxd = arcpy.mapping.MapDocument("C:/tmp/test.mxd")
mxd.saveACopy("C:/tmp/test3.mxd")
mxd.saveACopy("C:/tmp/test3.mxd")
mxd.saveACopy("C:/tmp/test2.mxd")
mxd.saveACopy("C:/tmp/test3.mxd")


is able to save test3.mxd the first and third times but not the second time, when if fails with error:

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.


Obviously, it's not a problem with overwriting the previous output, it's not a permissions issue, and it's not a storage space issue.

Separately, this code (in a fresh python session) also fails with the same error:

import arcpy
mxd = arcpy.mapping.MapDocument("C:/tmp/test.mxd")
mxd.saveACopy("C:/tmp/test2.mxd")


However, the same saveACopy code (in fresh python sessions each time) succeeds with C:/tmp/test3.mxd (as we've already seen), C:/tmp/tmp/test2.mxd, W:/test2.mxd, and W:/tmp/test2.mxd.
0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor
If you really want to call saveACopy to the same file name again and again (in the same script) then you will need to delete your map document variable reference that is holding onto the path.

import arcpy
mxd = arcpy.mapping.MapDocument("C:/temp/blank.mxd")
mxd.saveACopy(r"C:/temp/test3.mxd")
del mxd
mxd = arcpy.mapping.MapDocument("C:/temp/blank.mxd")
mxd.saveACopy(r"C:/temp/test3.mxd")
del mxd
mxd = arcpy.mapping.MapDocument("C:/temp/blank.mxd")
mxd.saveACopy(r"C:/temp/test2.mxd")
del mxd
mxd = arcpy.mapping.MapDocument("C:/temp/blank.mxd")
mxd.saveACopy(r"C:/temp/test3.mxd")
del mxd


Jeff
0 Kudos
OliverSoong
Emerging Contributor
I tested this a bit further and found out a bit more.  MapDocument.saveACopy seems to embed some attribute with the output filename in both the MapDocument object and the resulting mxd file.  MapDocument.saveACopy fails when writing to this same filename.  Alternating filenames works by alternating the embedded attribute in the MapDocument object.

I apparently created my test.mxd by saving a blank mxd, at some point calling mxd.saveACopy("C:/tmp/test2.mxd"), and later renaming it to test.mxd.  This explains why I only see problems with C:/tmp/test2.mxd and no other path, and only with this mxd.

BTW, I'm using Arc 10.1 SP1 and python 2.7.2.  ArcMap's Save, Save As, and Save A Copy do not seem to do this.
0 Kudos