[求助]用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没反应,高手帮帮忙 不知道,你引用了CAD的类型库没有? 是不是版本的问题啊? 我已经引用了 那位老大用的是cad2002帮我试试好不好用 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 如果用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
多谢老大,问题解决了 为什么有时会出现下面的情况
页:
[1]