- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have an vb.net application that take a list of drawings and open every one in Autocad, do some changes and print it. The application is an EXE file and works fine if Autocad is already running in the computer but fail if Autocad is not running yet. I'm working with visual studio 2015 and autocad 2018. This is the code that opens Autocad:
Imports System
Imports System.Runtime.InteropServices
Imports AutoCAD
Public Class cAcad
Public Sub RunAcad()
Dim ProgId As String = "AutoCAD.Application.22"
Dim AcApp As AcadApplication = Nothing
Try
AcApp = DirectCast(Marshal.GetActiveObject(ProgId), AcadApplication)
Catch ex As Exception
Try
Dim AcType As Type = Type.GetTypeFromProgID(ProgId)
AcApp = DirectCast(Activator.CreateInstance(AcType, True), AcadApplication)
Catch ex2 As Exception
MessageBox.Show("Cannot create object of type " & ProgId & vbNewLine & ex2.Message)
End Try
End Try
If AcApp IsNot Nothing Then
Try
AcApp.Documents.Add()
Catch ex As Exception
MessageBox.Show("Cannot add a new document " & ProgId & vbNewLine & ex.Message)
End Try
End If
End Sub
End Class
The error doesn't come in "createInstance", but it comes in "documents.add" sentence because Acad.exe is not running. The error is :
El servidor lanzó una excepción. (Excepción de HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).
I have tried many different ways to create the new object but always found the same problem.
Note: When createObject is running I can see Acad.exe in taskManager but when the sentence finish, acad.exe disapear.
Solved! Go to Solution.