VB

Public Sub LoadCadDrawingLayer()
  Dim pMxDoc As IMxDocument
  Dim pCadLayer As ICadLayer
  Dim pCadDrawingDataset As ICadDrawingDataset
 
  Set pMxDoc = Application.Document
  Set pCadDrawingDataset = GetCadDataset("F:/CAD文件/dwg", "105-604-15.dwg")
  If pCadDrawingDataset Is Nothing Then Exit Sub
  Set pCadLayer = New CadLayer
  Set pCadLayer.CadDrawingDataset = pCadDrawingDataset
  pCadLayer.Name = "e-51878.dwg" 'Give the map layer a name
  pMxDoc.FocusMap.AddLayer pCadLayer
  pMxDoc.UpdateContents 'Update the TOC
End Sub

Private Function GetCadDataset(strCadWorkspacePath As String, strCadFileName As String) As ICadDrawingDataset
  Dim pName As IName
  Dim pCadDatasetName As IDatasetName
  Dim pWorkspaceName As IWorkspaceName
 
  On Error GoTo ErrorHandler
 
  'Create a WorkspaceName object
  Set pWorkspaceName = New WorkspaceName
  pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.CadWorkspaceFactory"
  pWorkspaceName.PathName = strCadWorkspacePath
 
  'Create a CadDrawingName object
  Set pCadDatasetName = New CadDrawingName
  pCadDatasetName.Name = strCadFileName
  Set pCadDatasetName.WorkspaceName = pWorkspaceName
 
  'Open the CAD drawing
  Set pName = pCadDatasetName 'QI
  Set GetCadDataset = pName.Open
  Exit Function
 
ErrorHandler:
  Set GetCadDataset = Nothing
End Function


你可能感兴趣的:(GIS,开发与学习)