lorieme

findAndReplaceWorkspacePath removes layers from TOC

Discussion created by lorieme on Jan 17, 2011
Latest reply on Mar 1, 2011 by emerickr
The following script worked the first few times I used it, but now each of the layers whose workspace paths are fixed, are removed from the Table of Contents.

Code:

import arcpy, string


# access the current ArcMap mxd
mxd = arcpy.mapping.MapDocument("CURRENT")


brknlist = arcpy.mapping.ListBrokenDataSources(mxd)
for brknitem in brknlist:
    arcpy.AddMessage("Found Broken Link for Layer Name: " + brknitem.name)
    if brknitem.supports("WORKSPACEPATH"):
        oldsource = brknitem.workspacePath
        newsource = oldsource.replace("DOCS\GIS","GIS")
        newsource = newsource.replace("docs\gis","GIS")
        brknitem.findAndReplaceWorkspacePath(oldsource,newsource,False)
        arcpy.AddMessage(oldsource + " replaced by newsource: \n" + newsource + "\n")


#refresh
arcpy.RefreshTOC()
arcpy.RefreshActiveView()

del mxd

Outcomes