I was wondering what was the equivalent of "Save As" in ArcPy, which works perfectly fine in ArcMap. As the MXDs are currently set up with relative path moving MXD would break the links, however if MXD is saved with "Save As" option the links would be fine. I was trying to automate the procedure as there are too many files. SaveACopy (option 1) is breaking all links which is given below:
Option 1
import arcpy, os
srcdir = r"C:\temp\test1"
for basename in os.listdir(srcdir):
if basename.endswith('.mxd'):
mxdPathName = os.path.join(srcdir, basename)
mxd = arcpy.mapping.MapDocument(mxdPathName)
mxd.saveACopy(r"C:\temp\test1\test2\\" + basename)
I have tried to set the MXD to absolute path (option 2) and copy as a new copy which isn't working either (links are still broken).
Option 2
import arcpy, os
Workspace = r"C:\temp\test1"
arcpy.env.workspace = Workspace
mxdList = arcpy.ListFiles("*.mxd")
for file in mxdList:
filePath = os.path.join(Workspace, file)
filePathCopy = Workspace + r"test2\\" + file
mxd = arcpy.mapping.MapDocument(filePath)
mxd.relativePaths = False
mxd.save()
mxd.saveACopy(filePathCopy)
mxdCopy = arcpy.mapping.MapDocument(filePathCopy)
mxdCopy.save()
mxdCopy.relativePaths = True
mxdCopy.save()
mxd.relativePaths = True
mxd.save()