找到一些介绍文档,在vb的project/reference选择autocad release 15,我的cad是2002,没找到上述内容,只好选择autocad2002类型库,然后在vb窗体下设了个按钮,添加如下代码,可是cad怎么不画图呢?大家给看看:
Private Sub Command1_Click()
On Error Resume Next
Dim acadApp As AcadApplication
Set acadApp = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application") If Err Then MsgBox Err.Description Exit Sub End If End If MsgBox "Now running" + acadApp.Name + "vertion" + acadApp.Version
Dim acadDoc As AcadDocument Set acadDoc = acadApp.ActiveDocument
Dim lineObj As AcadLine Dim p1(2) As Double Dim p2(2) As Double p1(0) = 1: p1(1) = 2: p1(2) = 5 p2(0) = 100: p2(1) = 200: p2(2) = 0 Set lineObj = acadDoc.ModelSpace.AddLine(p1, p2) ZoomAll
End Sub
|