English

Bug: An error is generated when specifying 'NONE' as the workspace_type in the ArcPy mapping method replaceDataSource

Description

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.

Cause

This is a known issue at ArcGIS 10. For updates on the status, use bug number NIM058294.

Workaround

To avoid the error, specify a workspace_type parameter other than 'NONE'. See the link in the Related Information section below for a list of workspace_type parameters.

For example, change the following script:

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

to this:
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

    Related Information