Hi,
I work on several open mxd's and i try to save them at once with arcpy:
import arcpy,os,sys import arcpy.mapping from arcpy import env env.workspace = r"D:\PROJECTS\bat_galim\gis" for mxd in arcpy.ListFiles("*.mxd"): print mxd mapdoc = arcpy.mapping.MapDocument(r"D:\PROJECTS\bat_galim\gis\\" + mxd) mapdoc.save() print 'mapdoc.save' counter = counter + 1 del mxd
but i get en error:
IOError: 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.
what wrong with my code?
probably a path issues... for this ancient thread
see Filenames and file paths in Python
>>> mxd = "text.mxd" >>> path = r"D:\PROJECTS\bat_galim\gis\\" + mxd >>> path 'D:\\PROJECTS\\bat_galim\\gis\\\\text.mxd' # hmmmmmmm >>> path2 = r"D:\PROJECTS\bat_galim\gis" + "\\" + mxd >>> path2 'D:\\PROJECTS\\bat_galim\\gis\\text.mxd'
when i try to save opened MXD's i get an error. And my path is correct, so i don't see any reason to change it
and you confirmed that from my example... throw in a print statement and see what it returns and as James says, set overwriting to true
Maybe try to set the workspace Overwrite property?
arcpy.env.overwriteOutput = True
I enter this line in:
mapdoc.save() arcpy.env.overwriteOutput = True
And got this error:
IOError: 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.
it needs the full path to the mapdoc, or has to be 'current'. If you don't have write permission for whatever reasons it throws the message.
I'm not sure where you placed the line (it looks like you put it in the for loop?), but it should probably be located just after you set the workspace:
env.workspace = r"D:\PROJECTS\bat_galim\gis" env.overwriteOutput = True
i added it to this place- it still throws the same message. Maybe i wasn't clear in my question- the MXD's still open while i run this code. my propose was to save me to click on "save" buttun in all the open MXD's by my self- i wanted the python will do it.
so this what i did with this new row that James send me-there still an error.
Your code works fine for me. Double-check the folder and file permissions.