movie2003 发表于 2003-12-17 17:49:00

[求助]用vb怎么调用autocad2004

用vb怎么调用autocad2004,我试了怎么不行
Private Sub Command1_Click()

Dim acadapp As AcadApplication
On Error Resume Next
Set acadapp = GetObject("autocad.application.16")
If Err Then
Err.Clear
Set acadapp = CreateObject("autocad.application.16")
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
Dim polyobj As AcadLWPolyline
Dim acaddoc As AcadDocument
Set acaddoc = acadapp.ActiveDocument
Dim sta(0 To 5) As Double
sta(0) = 1
sta(1) = 1
sta(2) = 2
sta(3) = 2
sta(4) = 2
sta(5) = 1
Set polyobj = acaddoc.ModelSpace.AddLightWeightPolyline _
(sta)
polyobj.Closed = True
End Sub
试过后cad没反应,高手帮帮忙

topirol 发表于 2003-12-17 17:53:00

不知道,你引用了CAD的类型库没有?

gzy 发表于 2003-12-17 18:07:00

是不是版本的问题啊?

movie2003 发表于 2003-12-17 18:34:00

我已经引用了

movie2003 发表于 2003-12-17 18:38:00

那位老大用的是cad2002帮我试试好不好用

sdxylijian 发表于 2003-12-18 02:09:00

On Error Resume Next '错误处理
Set AcadApp = GetObject(, "autocad.application") '启动AutoCAD
If Err Then
    Err.Clear '清理错误
    Set AcadApp = CreateObject("autocad.application")
    If Err Then
    MsgBox Err.Description
    Exit Sub
    End If
End If

zeng29 发表于 2003-12-18 08:37:00

如果用GetObject或CreateObject则不用引用AutoCAD类型库,但你的GetObject用法有错误!
CAD的进程及所有实体都须声明为Object.在不需要错误陷阱的时候要关闭,以便调试.

Private Sub Command1_Click()

Dim acadapp As Object
On Error Resume Next
Set acadapp = GetObject(, "AutoCAD.Application.16")
If Err Then
Err.Clear
Set acadapp = CreateObject("autocad.application.16")
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
acadapp.Visible = True
On Error GoTo 0
Dim polyobj As Object
Dim acaddoc As Object
Set acaddoc = acadapp.ActiveDocument
Dim sta(0 To 5) As Double
sta(0) = 1
sta(1) = 1
sta(2) = 2
sta(3) = 2
sta(4) = 2
sta(5) = 1
Set polyobj = acaddoc.ModelSpace.AddLightWeightPolyline _
(sta)
polyobj.Closed = True
End Sub

movie2003 发表于 2003-12-19 07:52:00

多谢老大,问题解决了

movie2003 发表于 2003-12-19 19:59:00

为什么有时会出现下面的情况

页: [1]
查看完整版本: [求助]用vb怎么调用autocad2004