不过,我通过大量试验得出了这个结论。我现在已经通过COM创建了一个独立的应用程序。我可以启动AutoCAD,但当我发送命令时,我得到“加载失败”
你能指出我的代码有什么问题吗?
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
- Const progID As String = "AutoCAD.Application.19.1"
- Dim acApp As AcadApplication = Nothing
- Dim LispPath As String = "..."
- Dim My_Lisp As String = "SMBTEST"
- Dim Cmd_To_Start_LISP_Program As String = "SMBRUN"
- Try
- acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication)
- Catch
- Try
- Dim acType As Type = Type.GetTypeFromProgID(progID)
- acApp = DirectCast(Activator.CreateInstance(acType, True), AcadApplication)
- Catch
- MessageBox.Show("Cannot create object of type """ + progID + """")
- End Try
- End Try
- If acApp IsNot Nothing Then
- acApp.Visible = True
- acApp.ActiveDocument.SendCommand("(load """ & LispPath & My_Lisp & ".lsp"" ""The load failed"") " & Cmd_To_Start_LISP_Program & Chr(13))
- End If
- End Sub
|