Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jan 10 '12 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_ Jan 10 '12 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 Feb 27 '12 at 7:20

2 Answers 2

up vote 1 down vote accepted

Logged as bug by ESRI:

Bug #NIM078454

share|improve this answer

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. Workaround to the workaround?

share|improve this answer
    
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_ Jun 4 '13 at 1:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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