# 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()
Solved! Go to Solution.
import arcpy from arcpy import env from arcpy import mapping arcpy.env.workspace = workspace = "C:\GIS\MAPBOOK\Proposed Zoning Book" arcpy.env.overwriteOutput = True mxdList = arcpy.ListFiles("*.mxd") for mxd in mxdList: mxd = workspace + "\\" + mxd print mxd + " is being processed" mxd = arcpy.mapping.MapDocument(mxd) for df in arcpy.mapping.ListDataFrames(mxd, "*"): for lyr in arcpy.mapping.ListLayers(mxd, "*", df): mxd.findAndReplaceWorkspacePaths(r"C:\Documents and Settings\***\Application Data\ESRI\ArcCatalog\***.sde",r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.***.VECTOR.sde") print "Successfully updated data sources" mxd.save()
import arcpy from arcpy import env from arcpy import mapping workspace = arcpy.env.workspace = "C:\GIS\MAPBOOK\Proposed Zoning Book" arcpy.env.overwriteOutput = True mxdList = arcpy.ListFiles("*.mxd") for mxd in mxdList: mxd = workspace + "\\" + mxd print mxd + " is being processed" mxd = arcpy.mapping.MapDocument(mxd) mxd.findAndReplaceWorkspacePaths(r"C:\Documents and Settings\***\Application Data\ESRI\ArcCatalog\***.sde",r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DBO.***.VECTOR.sde") print "Successfully updated data sources" mxd.save(r'new_mxd_filename.mxd'))
mxd.replaceWorkspaces(r"O:\GIS\COUNTY MAPS\Proposed Zoning\ProposedZonningAreas_Erase_E1.shp", "SHAPEFILE_WORKSPACE", r"O:\GIS\COUNTY MAPS\Proposed Zoning\FutureLandUseZoning_8_4_2011.shp", "SHAPEFILE_WORKSPACE")
import arcpy from arcpy import env from arcpy import mapping arcpy.env.workspace = workspace = "C:\GIS\MAPBOOK\Proposed Zoning Book" arcpy.env.overwriteOutput = True mxdList = arcpy.ListFiles("*.mxd") for mxd in mxdList: mxd = workspace + "\\" + mxd print mxd + " is being processed" mxd = arcpy.mapping.MapDocument(mxd) for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == "CITY LIMITS": lyr.replaceDataSource(r"C:\Users\talmeida\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\DSD15_SQLEXPRESS.gds\TonyOneWay\TonyOneWay.DBO.Canyon_Features", "FILEGDB_WORKSPACE", "TonyOneWay.DBO.City_Limits") print "Successfully updated data sources" mxd.save()
This is marked as solved but the last post indicates that it may not be.
Is it the case that the original map document cannot be saved? I noticed that ArcCatalog's Set Data Source does not save the original but instead saves a copy. Maybe writing a new map document would be a workaround (less than ideal).