Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Changing Data Source on MXD

$
0
0
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.

Proposed_ZoningMapBook_Page_1.mxd

Traceback (most recent call last):
File "C:/GIS/Python Scripts/Change Data Source MXD.py", line 29, in <module>
MXD.replaceWorkspaces(source, "SDE_WORKSPACE", datapath, "SDE_WORKSPACE")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\_mapping.py", 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
Code:

# 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
                MXD.save()


Viewing all articles
Browse latest Browse all 2485

Trending Articles