I have an MXD. It connects to about 30 layers in one of our SDE databases. I want to change the SDE database they connect to.
Is there a way to do this without having to right-click every layer and change it individually?
Right click on the mxd in ArcCatalog, click on Set data sources, and bulk change from there. However, this tool warns:
Note: this dialog is intended primarily for preparing map documents for publication. Customizations (VBA code, UI Controls and custom toolbars), graphs, and table window appearance properties are removed from .mxd files when you update their data sources using this dialog. To preserve these, update the data sources in ArcMap instead.
You could also use the arcpy.mapping python library:
If you are using ArcGIS 10 and are interested in using Python, check out the help on Updating and fixing data sources with arcpy.mapping and the methods of the Layer object.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project_SDE1.mxd") mxd.findAndReplaceWorkspacePaths(r"Database Connections\Connection to GISSDE1.sde", r"Database Connections\Connection to GISSDE2.sde") mxd.saveACopy(r"C:\Project\Project_SDE2.mxd") del mxd
If your layers don't all source the same original connection file, or the destination feature class name is different on the new SDE, you might need to use
This will remove all the red exclamation mark containing layers in the MXD and will point to the new created data source. In one go you can do this; no need to go and click each time on the red exclamation mark and clicking and setting the data source.
The link is to an old Arcscript called GDK tools, wich can be obtained on other sites. The Program creates a toolbar in arcmap where you can change source on selected layers (any layer you want. this works between SDE connections or SDE to local file geodatabase (wich change source in Arccatalog not can handle, because of the name in SDE starts with the SDE user and then dot.
this is very helpful, but maybe only in arcgis 9.3
For one mxd, default ESRI tools can suffice. But fixing multiple mxds with broken links can be a nightmare. Try my UpdateLayerRefs tool to fix unlimited MXDs in seconds: https://github.com/jswagger/UpdateLayerRefs Just provide the names of your input MXD's as a list ["Name1.mxd", "Name2.mxd", "Name3.mxd"]
If you've got the .mxd open already, do what @blah238 did, but use
'CURRENT' instead of the full path. Don't forget that the search and replace doesn't have to be the full string:
import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') mxd.findAndReplaceWorkspacePaths(r"scratch", r"project/draft")
Then you'll have to save and reopen the .mxd file anyway.
Seems like this post is old, but i can't get this to work: Code is as follows:
import arcpy, glob #specify MXD location to change source data mxd = arcpy.mapping.MapDocument(r"C:\\Users\\jrender\\Documents\\LandbaseEditing PreProd Pub Check.mxd") workspaceCurrent = r"Database Connections\Connection to PP_GISLand_Landbase.sde" workspaceTarget = r"Database Connections\Connection to PP_Publication_GISLand.sde" mxd.findAndReplaceWorkspacePaths(workspaceCurrent, workspaceTarget) #save a new copy of MXD mxd.saveACopy(r"C:\Users\jrender\Documents\LandbaseEditing PreProd Pub Check Repathed.mxd")