I am trying to load AutoCad from my programe. The code is:
Private Sub LoadAcad(ByVal fn As String)
Dim acadApp As AcadApplication
Dim acadDoc As AcadDocument
Dim ProgId As String = "AutoCAD.Application"
Try
acadApp = GetObject(, ProgId)
With acadApp
.Visible = True
acadDoc = .Documents.Open(fn, False)
End With
I catch the error that AutoCad is not loaded so I load it
Catch ex1 As Exception
Try
acadApp = CreateObject(ProgId)
With acadApp
.Visible = True
acadDoc = .Documents.Open(fn, False)
End With
At this point AutoCad is loaded because I see a bit of it before it disappears, and it is there in the Windows Task Manager, but I don't know whether drawing "fn" was loaded. It then raises the exception "Cannot create ActiveX component."
Which is why I have captured the second error.
Catch ex2 As Exception
MsgBox(ex2.Message & vbCrLf & "Try Again")
End Try
End Try
End Sub
Now if I then execute this code again (from the form's button) it works. Except "fn" is always loaded read-only. I have checked it's attribues just before and it reports that it is Normal.
Any ideas?