在VB中如何实现相对路径调用CAD应用程序~~~~
发布网友
发布时间:2022-04-22 10:31
我来回答
共2个回答
热心网友
时间:2023-09-24 18:08
Private Sub Command1_Click()
'首先引用 acad 2009 Object Library类型库
Dim myAcadApp As AutoCAD.AcadApplication, activeDoc As AutoCAD.AcadDocument, acMS As AutoCAD.AcadModelSpace
On Error Resume Next
Set myAcadApp = GetObject(, "Autocad.Application") '检查AutoCAD是否已经打开
If Err <> 0 Then '没有打开
Err.Clear
Set myAcadApp = CreateObject("Autocad.Application") '打开CAD
If Err Then
MsgBox Err.Number & ":" & Err.Description '打开失败
Exit Sub
End If
End If
On Error GoTo prcERR
myAcadApp.Visible = True '显示CAD
Set activeDoc = myAcadApp.ActiveDocument
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double
Dim LineObj As AcadLine'如果画图时出错,改为Dim LineObj As Object
startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0
endPoint(0) = 30: endPoint(1) = 20: endPoint(2) = 0
Set LineObj = activeDoc.ModelSpace.AddLine(startPoint, endPoint) '画线
prcExit:
Set activeDoc = Nothing
Set myAcadApp = Nothing
Exit Sub
prcERR:
MsgBox Err.Number & ":" & Err.Description, vbCritical, "错误"
Resume prcExit
End Sub
热心网友
时间:2023-09-24 18:08
引用就行了