This macro adds each CAD file layer as a separate feature layer in the focus map. See the How to add a CAD drawing layer for an example showing how to add an entire CAD file in one CAD drawing layer.
How to use
- Open ArcMap and paste the code into VBA.
- Modify the code to point to a CAD file on your system.
- Run the routine from the Macros dialog.
Public Sub LoadCadDrawingLayers()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pCadWKSFact As IWorkspaceFactory
Dim pWorkspace As IFeatureWorkspace
Dim pCadFeatureLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pFeatureDataset As IFeatureDataset
Dim pFeatureClassContainer As IFeatureClassContainer
Dim Count As Integer
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pCadWKSFact = New CadWorkspaceFactory
Set pWorkspace = pCadWKSFact.OpenFromFile("d:\data\cad", 0)
Set pFeatureDataset = pWorkspace.OpenFeatureDataset("e-51878.dwg")
Set pFeatureClassContainer = pFeatureDataset
For Count = 0 To pFeatureClassContainer.ClassCount - 1
Set pFeatureClass = pFeatureClassContainer.Class(Count)
'Check for annotation
If pFeatureClass.FeatureType = esriFTCoverageAnnotation Then
Set pCadFeatureLayer = New CadAnnotationLayer
Else
Set pCadFeatureLayer = New CadFeatureLayer
End If
pCadFeatureLayer.Name = pFeatureClass.AliasName 'Give the map layer a name
Set pCadFeatureLayer.FeatureClass = pFeatureClass
pMap.AddLayer pCadFeatureLayer
Next Count
pMxDoc.UpdateContents 'Refresh the TOC
End Sub