Created
March 25, 2015 18:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# @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