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 =D
I have a CSV file from which I am reading four columns of which I will give an example below:
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:
Then I loop through the rows in the CSV and compare it to the layer data source using the following code
if layer.supports("DATASOURCE") and layer.supports("WORKSPACEPATH"):
which is equivalent to something like
if os.path.join(row, row) == 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'
if "C:\CAD_Directory\CAD_File.dxf\Polyline" == layer.dataSource:
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)
Where as my code looks like this:
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.
layer.replaceDataSource(r"X:\New_CAD_Directory\CAD_File_1.dxf", "CAD_WORKSPACE", layer.name)