ReplaceDataSource not working in script

4425
10
07-20-2010 04:10 AM
ChristianHalsted
New Contributor II
I am trying to write a script tool that will loop through all the disconnected layers in a map document and repoint them using the Layer.replaceDataSource function.  When I run the following 3 lines of code:

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListBrokenDataSources(mxd)[0]
lyr.replaceDataSource(r"Database Connections\GISUSER on dep-eia1dbsop01.sde","SDE_WORKSPACE",r"Sample_Location",True)

from the Python Window within ArcGIS Desktop it works fine.  But when I put them in a .py file and try to run the script from ArcToolbox it seems to reconnect the file but then removes it from the map document.
0 Kudos
10 Replies
HenkZwols
Occasional Contributor
I'm having the same issue when running my python script. 

It connects the layers fine, then immediately removes them.

Is this a known bug?


I have the same problem: after setting the source, the layer is removed from the TOC.
What's happening?

Greetings, Henk
0 Kudos