AnsweredAssumed Answered

Programmatically change CAD Layer's data source

Question asked by tchapin on Feb 7, 2020
Latest reply on Feb 11, 2020 by tchapin

I am trying to change the data source of a CAD layer in a Pro map using arcpy. Looking at the documentation on the arcpy.mp.Layer class I can see that the updateConnectionProperties method is the one to use. Get the connection properties dictionary from the existing layer, change what needs to be changed, and give the new connection properties to this method. But, the connectionProperties does not include the name of the drawing file, just the folder containing the file.

 

Here's an example: I have 2 layers in a Pro map from the Polyline layer of 2 different drawings, MyDrawing1.dwg and MyDrawing2.dwg in the same folder C:\CAD DataSources.

 

Here are the connectionProperties for MyDrawing1.dwg/Polyline:

arcpy.mp.ArcGISProject("CURRENT").activeMap.listLayers()[0].connectionProperties

{'dataset': 'Polyline', 'workspace_factory': 'Cad', 'connection_info': {'database': 'C:\\CAD DataSources'}}

 

Here are the connectionProperties for MyDrawing2.dwg/Polyline:

arcpy.mp.ArcGISProject("CURRENT").activeMap.listLayers()[1].connectionProperties

{'dataset': 'Polyline', 'workspace_factory': 'Cad', 'connection_info': {'database': 'C:\\CAD DataSources'}}

 

 

They are exactly the same, so my_layer.updateConnectionProperties(current_connection_info, new_connection_info) does nothing.

 

The dataSource property reflects the dwg file name, but I don't see how that property plays in the updateConnectionProperties method, and that property is read-only.

arcpy.mp.ArcGISProject("CURRENT").activeMap.listLayers()[0].dataSource

'C:\\CAD DataSources\\MyDrawing1.dwg\\Polyline'

arcpy.mp.ArcGISProject("CURRENT").activeMap.listLayers()[1].dataSource

'C:\\CAD DataSources\\MyDrawing2.dwg\\Polyline'

 

 

Using the Set Data Sources GUI correctly reassigns the layer's data source.

Outcomes