The message you are trying to access is permanently deleted.
import arcpy, os, gc def Test(): # Test mode justSaveAs = True # Test MXD originalDoc = r"C:\Users\USERNAME\Documents\ArcGIS\TestData\Test.mxd" # Make a new MXD Name... baseFldr = os.path.dirname(originalDoc) baseName = os.path.basename(originalDoc) newDoc = os.path.join(baseFldr,"temp123_" + baseName) # Open the original Document, and save a copy mxd = arcpy.mapping.MapDocument(originalDoc) mxd.saveACopy(newDoc) # Close the document del mxd gc.collect() # Delete the original and rename the new file the same as the original os.remove(originalDoc) os.rename(newDoc,originalDoc) if justSaveAs: # Reopen the document and try and save as again -- FAILS mxd = arcpy.mapping.MapDocument(originalDoc) mxd.saveACopy(newDoc) else: # Reopen the document, save, then save as -- WORKS!? mxd = arcpy.mapping.MapDocument(originalDoc) mxd.save() mxd.saveACopy(newDoc)
originalDoc = r'C:\temp\Untitled.mxd' # Make a new MXD Name... baseFldr = os.path.dirname(originalDoc) baseName = os.path.basename(originalDoc) newDoc = os.path.join(baseFldr,"temp123_" + baseName) # Open the original Document, and save a copy mxd = arcpy.mapping.MapDocument(originalDoc) mxd.saveACopy(newDoc) mxd = arcpy.mapping.MapDocument(newDoc) mxd.saveACopy(originalDoc) mxd = None
originalDoc = r'C:\temp\Untitled.mxd' # Make a new MXD Name... baseFldr = os.path.dirname(originalDoc) baseName = os.path.basename(originalDoc) old_doc = os.path.join(baseFldr,"orig_" + baseName) # make a copy of the original with a new name shutil.copy2(originalDoc, old_doc) # Open the original Document, do the work, and set work_done flag mxd = arcpy.mapping.MapDocument(originalDoc) # do some work here if necessary, set flag depending on if #anything was done or not. We'll set to true for demonstration work_done = True if work_done: mxd.save() # move the original to an archive folder afol = r'C:\temp\Archive' dest = os.path.join(afol, baseName) shutil.move(old_doc, dest) else: os.remove(old_doc) mxd = None