Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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. It's really holding me up. I'm using ArcInfo 10.0 SP4.

Thanks in advance.

share|improve this question
add comment

1 Answer 1

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
    
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 '12 at 22:52
1  
@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
add comment

Your Answer

 
discard

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.