BUG
The ArcPy mapping module provides two replaceDataSource methods: Layer.replaceDataSource and TableView.replaceDataSource. 'NONE' is a valid value for the workspace_type parameter. When 'NONE' is specified, the workspace type native to the Layer or TableView being worked with should be used by the application. Instead, an error is returned.
This is a known issue at ArcGIS 10. For updates on the status, use bug number NIM058294.
Code:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
if lyr.supports("DATASOURCE"):
if lyr.dataSource == r"C:\Project\Data\Transportation.gdb\MajorRoads":
lyr.replaceDataSource(r"C:\Project\Data\Transportation.gdb", "NONE", "Highways")
lyr.name = "Highways"
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd
Code:
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
if lyr.supports("DATASOURCE"):
if lyr.dataSource == r"C:\Project\Data\Transportation.gdb\MajorRoads":
lyr.replaceDataSource(r"C:\Project\Data\Transportation.gdb", "FILEGDB_WORKSPACE", "Highways")
lyr.name = "Highways"
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd
Article ID:000010963
Get help from ArcGIS experts
Download the Esri Support App