1

I am having trouble replacing the data source on CAD files using arcpy.

Everything I have tried runs into this error:

Runtime error type 'exceptions.ValueError' : Layer: Unexpected error

Here is a list of arguments I have tried:

layer.replaceDataSource('C:/CAD_DIR/CAD_File_1.dxf', 'CAD_WORKSPACE', 'Polyline')

layer.replaceDataSource('C:/CAD_DIR/CAD_File_1', 'CAD_WORKSPACE', 'Polyline')

layer.replaceDataSource('C:/CAD_DIR/', 'CAD_WORKSPACE', 'CAD_File_1/Polyline')

layer.replaceDataSource('C:/CAD_DIR/', 'CAD_WORKSPACE', 'CAD_File_1.dxf/Polyline')

layer.replaceDataSource('C:/CAD_DIR/', 'CAD_WORKSPACE', 'CAD_File_1.dxf.Polyline')

layer.replaceDataSource('C:/CAD_DIR/', 'CAD_WORKSPACE', 'CAD_File_1.Polyline')

It appears to take more time to think about going wrong when I put the 'CAD_File_1*' part in the 'Dataset_Name' section, that is to the right of 'CAD_WORKSPACE'. But it still fails.

I have noticed that it treats the CAD file as a Feature Dataset and the particular feature type, in this case Polyline, as the Feature Class which may be the issue.

I have also tried this when pointing at a 'Polyline' layer:

layer.replaceDataSource('C:/CAD_DIR/', 'CAD_WORKSPACE', 'CAD_File_1.dxf)

It doesn't produce the same error or in fact any error but the data does not update.

3
  • You used double quotation marks at the beginning of the first parameter (") but ended with single quotation marks ('). Sometimes it doesn't make a difference, but since ValueError is parameter-related you want to make sure those string parameters are being passed properly.
    – dmahr
    Commented Jan 10, 2012 at 12:55
  • Good point, but that is just my mistake when writing the example here. For the most part I am trying to make changes in batch so syntax like that is assigned automatically when I pull the string from a CSV. I will edit to remove that mistake. Thanks.
    – EnE_
    Commented Jan 10, 2012 at 23:14
  • If this is still an issue there is some discussion here that may or may not help: forums.arcgis.com/threads/…
    – PolyGeo
    Commented Feb 27, 2012 at 7:20

2 Answers 2

2

Logged as bug by ESRI:

Bug #NIM078454

1

Bug indeed, but since I am stuck on 10.0 for another year the 10.1 fix didn't help me yet. Since this is still one of the first results on my Google search for the topic, I thought I'd come back and add my answer.

The workaround here solved the issue for me. To summarize, save a reference to the layer, remove the later from the map document, update the data source, and re-add it.

I was unable to replace CAD sources properly, but ended up using the 'NONE' keyword for the workspace_type parameter and it looped through the sources in the new folder until it found one with the name specified.

1
  • Thanks for the update brichins, I haven't looked at that code for about 18 months now. When I get a chance I will check it out.
    – EnE_
    Commented Jun 4, 2013 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.