Thanks for your help.I have had a look at your code and I am still not able to figure out where I am going wrong but I am hoping if I explain what I am doing a little more clearly it will help you help me =DI have a CSV file from which I am reading four columns of which I will give an example below:ORIGINAL_NAME_COLUMN: "Polyline"ORIGINAL_PATH_COLUMN: "C:\CAD_Directory\CAD_File.dxf"NEW_NAME_COLUMN: "Polyline"NEW_PATH_COLUMN: "X:\New_CAD_Directory\CAD_File_1.dxf"I think it is important to note that I have changed the name of the CAD file which may be where I am falling down.For each layer to get rid of group layers etc I run:
if layer.supports("DATASOURCE") and layer.supports("WORKSPACEPATH"):
Then I loop through the rows in the CSV and compare it to the layer data source using the following code
if os.path.join(row[1], row[0]) == layer.dataSource:
which is equivalent to something like
if "C:\CAD_Directory\CAD_File.dxf\Polyline" == layer.dataSource:
If this succeeds I attempt to change the data source. As the Data Source in 'layer.DataSource' goes to the full DXF path then I have assumed this would be the code for the 'ReplaceDataSource'Now from your code I understand that you are pointing to a directory rather than the DXF as the data source. To continue using my example above Your code would be similar to:
layer.replaceDataSource(r"X:\New_CAD_Directory", "CAD_WORKSPACE", layer.name)
OR
layer.findAndReplaceWorkspace(r"C:\CAD_Directory", r"X:\New_CAD_Directory")
Where as my code looks like this:
layer.replaceDataSource(r"X:\New_CAD_Directory\CAD_File_1.dxf", "CAD_WORKSPACE", layer.name)
OR
layer.findAndReplaceWorkspace(r"C:\CAD_Directory\CAD_File.dxf", r"X:\New_CAD_Directory\CAD_File_1.dxf")
If the Data Source is only to the directory level then I am uncertain as to how to map to a new DXF name. Particularly if there are several CAD files in there as I would assume that it automatically use the original CAD file name if pointing to a directory. If the Data Source goes to the DXF level then I don't know why it is falling over.