如果用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
|