AnsweredAssumed Answered

Changing Data Source on MXD

Question asked by Tonyalmeida on Jul 31, 2013
Latest reply on Aug 2, 2013 by Tonyalmeida
I am needing to change my multiple layers Data Source in about 24 MXD's from one sde geodabase to a different. We have changed servers. My SDE instance is different now. Note: there is no passwords and there is some .shp files in this mxd

I am getting the following error. so any help would be gratefully appreciated.


Traceback (most recent call last):
  File "C:/GIS/Python Scripts/Change Data Source", line 29, in <module>
    MXD.replaceWorkspaces(source, "SDE_WORKSPACE", datapath, "SDE_WORKSPACE")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line 915, in replaceWorkspaces
    return convertArcObjectToPythonObject(self._arc_object.replaceWorkspaces(*gp_fixargs((old_workspace_path, old_workspace_type, new_workspace_path, new_workspace_type, validate), True)))
ValueError: MapDocObject: Unexpected error
# Import system modules import arcpy, os, glob  #This is the folder containing your MXD's arcpy.env.workspace = "C:\GIS\MAPBOOK\Proposed Zoning Book"   wrksp3 = arcpy.env.workspace arcpy.env.workspace = wrksp3   #Lets grab a listing of all MXD's in our workspace; called wrksp3 for filename in os.listdir(wrksp3):     fullpath = os.path.join(wrksp3, filename)     if os.path.isfile(fullpath):         basename, extension = os.path.splitext(fullpath)         if extension.lower() == ".mxd":             print filename                         MXD = arcpy.mapping.MapDocument(fullpath)             #list all the layers in the first MXD from above             for lyr in arcpy.mapping.ListLayers(MXD):                 #print lyr                 #Here we grab the source from the first layer                 source = lyr.workspacePath                 #print lyr, source                 #This is the NEW SOURCE that your point to                 datapath = r"C:\Users\**\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.**.**.sde"                 #Here the actual source replacement is done                 MXD.replaceWorkspaces(source, "SDE_WORKSPACE", datapath, "SDE_WORKSPACE")                 #dont forget to save your changes; this option saves the MXD to v10, no saving as pre-10 versions of ArcGIS