Recently we did an upgrade from ArcGIS 10.2.2 to 10.3.1. Our Administrator has left the old server on because of other issues. I would still like to switch all database connections over to our new .sde from the old one. I have followed the "Updating and f

127
2
11-09-2017 10:33 AM
Highlighted
New Contributor III

>>> import arcpy
... mxd = arcpy.mapping.MapDocument(r"P:\filepath_of_my_map_document.mxd")
... mxd.findAndReplaceWorkspacePaths("C:\Users\MyUsername\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\old server.sde", r"C:\Users\MyUsername\AppData\Roaming\ESRI\Desktop10.3\ArcCatalog\new server.sde")
... mxd.saveACopy(r"P:\filepath_of_my_map_document.mxd2.mxd")
... del mxd

Reply
0 Kudos
2 Replies
Highlighted
Occasional Contributor

Hello,

Try following python script :

import arcpy, os, string
#starting folder location where old mxds reside
path = r"D:\Map Documents" #CHANGE TO FOLDER DIRECTORY TO MXDS
#Path to log file
text = r"D:\Map Documents\textfile\errorlogs.txt" #CHANGE TO ANY DIRECTORY TO WRITE A LOGGING TEXT FILE
mxdtext = r"D:\Map Documents\textfile\mxdlogs.txt" #CHANGE TO ANY DIRECTORY TO WRITE A LOGGING TEXT FILE
outLog = open(text, "w")
mxdLog = open(mxdtext, "w")

#Path to output data
mxd_dir = r"D:\Map Documents\new mapdocument" #CHANGE TO NEW FOLDER FOR NEW RESOURCED MXDS
for root, dirs, files in os.walk(path):
       
    for name in files:
        if name.endswith(".mxd"):
           
            mxd_name = name
            fullpath = os.path.join(root,name)
            print "Evaluating {0}".format(fullpath)
            mxd = arcpy.mapping.MapDocument(fullpath)
           
            newSdePath = r"C:\Users\anjalido\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\abc_sde.sde"
            oldpath = ""
                                
            try:
               
                mxd.replaceWorkspaces(oldpath, "NONE", newSdePath, "SDE_WORKSPACE")
         
                print "Replaced"
                                                               
            except:
               
                outLog.write("Errors: " + str(arcpy.AddError(arcpy.GetMessages(1))))
                outLog.write("\n")
                outLog.write("Errors: " + str(arcpy.AddError(arcpy.GetMessages(2))))
                outLog.write("\n")
                outLog.write("Errors: " + str(arcpy.AddError(arcpy.GetMessages(3))))
                outLog.write("\n")
                  
                       
            #mxd.save()
            mxd.saveACopy(mxd_dir + os.sep + mxd_name)
            print "Saved mxd: {0}".format(mxd_name)
            mxdLog.write("Saved: {0}".format(str(mxd_name)))
            mxdLog.write("\n")
           
outLog.close()
mxdLog.close()

Hope this helps!

Highlighted
Honored Contributor

What error did you get, if any?

Reply
0 Kudos