Skip to content

Instantly share code, notes, and snippets.

@cindygis
Created March 25, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cindygis/4d7a662edab0f8950927 to your computer and use it in GitHub Desktop.
Save cindygis/4d7a662edab0f8950927 to your computer and use it in GitHub Desktop.
Replace data sources of layers in a map document using two different methods.
#
# @date 25/03/2015
# @author Cindy Williams
#
# Replace data sources of layers in a mxd using
# two different methods.
#
# For use in the Python window in ArcMap.
#
mxd = arcpy.mapping.MapDocument("CURRENT")
sde_old = r"C:\Database Connections\old.sde"
sde_new = r"C:\Database Connections\new.sde"
mxd.findAndReplaceWorkspacePaths(old, new)
# If the above does not work because ArcMap is being ArcMap
lyrs = arcpy.mapping.ListLayers(mxd)
for lyr in lyrs:
lyr.replaceDataSource(new, "SDE_WORKSPACE", lyr.datasetName)
arcpy.RefreshTOC()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment