给你完整代码 Private Sub Command1_Click() 'AutoCAD与visual basic连接 On Error Resume Next Set obj_Acad = GetObject(, "autocad.application") If Err Then Err.Clear On Error Resume Next Set obj_Acad = CreateObject("autocad.application") If Err Then Err.Clear MsgBox "不能运行AutoCAD,请检查是否安装!", vbOKCancel, "警告!" Exit Sub End If End If obj_Acad.Visible = True Set obj_Doc = obj_Acad.ActiveDocument Set obj_ModelSpace = obj_Doc.ModelSpace Dim xrefInserted As Object Dim insertionPnt(0 To 2) As Double Dim PathName As String Dim tempBlock As Object Dim msg As String insertionPnt(0) = 10: insertionPnt(1) = 100: insertionPnt(2) = 0 PathName = "D:\Personal\My Documents\My eBooks\border60.dwg" Set xrefInserted = obj_ModelSpace.AttachExternalReference(PathName, "WXREF", insertionPnt, 1, 1, 1, 0, False) GoSub ListBlocks Exit Sub
ListBlocks: msg = vbCrLf For Each tempBlock In obj_Doc.Blocks msg = msg & tempBlock.Name & vbCrLf Next MsgBox "图中包含的块有: " & msg Return End Sub ************************************************************* 西北凡人-----http://www.abofanyi.com/blog |