import arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd2 = workspace + "\\" + mxd
mapdoc = arcpy.mapping.MapDocument(mxd2)
mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\VECTOR_QAQC.sde")
mapdoc.save()
del mapdocimport arcpy
from arcpy import env
env.workspace = workspace = r"C:\temp\python"
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd2 = workspace + "\\" + mxd
mapdoc = arcpy.mapping.MapDocument(mxd2)
mapdoc.findAndReplaceWorkspacePaths(r"C:\TEMP\Python\VECTOR_Default.sde", r"C:\TEMP\Python\RASTER_Default.sde")
mapdoc.save()
del mapdoc
import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = workspace = arcpy.GetParameterAsText(0)
env.overwriteOutput = True
mxdList = arcpy.ListFiles("*.mxd")
for mxd in mxdList:
mxd = workspace + "\\" + mxd
print mxd + " is being processed"
mxd = mapping.MapDocument(mxd)
for df in mapping.ListDataFrames(mxd, "*"):
for lyr in mapping.ListLayers(mxd, "*", df):
lyr.replaceDataSource(arcpy.GetParameterAsText(1), "SDE_WORKSPACE", "")
print "Successfully updated data sources"
mxd.save()
del mxd
How do i find the path to the different versions in my SDE ? to use this method ( switch data sources from one version to another)
I only see the SDE name not the path for different versions?
Joe Head the version will be controlled through the .sde connection file. If you wan to connect to a different version, create a connection to your enterprise geodatabase > right-click on the connection > Geodatabase Connection Properties. Below is a helpful document:
Connect to a specific geodatabase version—Help | ArcGIS Desktop
I understand how to do this with the GUI but I wanted to write a script to change all Layer Data sources within an MXD from Version 1 to version 2 within the same SDE.
Joe Head once you create the .sde connection file to version 2 using the GUI, have the script point to this .sde connection file and you're all set. You can also create the .sde connection file using the Create Database Connection tool.