Saturday 16 February 2019

arcpy - AttributeError: MapDocObject: Unable to save on mxd.save/saveACopy?


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
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.



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...