If I run the "OpenDrawing" from a command prompt inside of AutoCAD (after AutoCAD is "ready") everything works perfectly. However, if I try to run the "OpenDrawing" subroutine as part of the "autoload" functionality I get most of the message boxes, but the drawing doesn't open. I feel this is because AutoCAD is not "all the way open" when the subroutine executes. Does anyone have an idea how to resolve this issue?
Code:
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports System.IO
Public Class clsInitialize
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub subInitialize() Implements IExtensionApplication.Initialize
MsgBox("Plugin loaded successfully . . .")
OpenDrawing() 'IF THIS LINE IS OMITTED,
End Sub
Public Sub subTerminate() Implements IExtensionApplication.Terminate
MsgBox("Plugin unloaded . . . ")
End Sub
<CommandMethod("OpenDrawing", CommandFlags.Session)> _
Public Sub OpenDrawing()
Dim strDrivePathNameExt As String
Dim colAcadDocs As DocumentCollection 'ApplicationServices
MsgBox("OpenDrawing Sub")
strDrivePathNameExt = "C:\Temp\Junk.dwg"
colAcadDocs = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
MsgBox("Here1")
If (File.Exists(strDrivePathNameExt)) Then 'System.IO
MsgBox("Here2")
DocumentCollectionExtension.Open(colAcadDocs, strDrivePathNameExt, False)
MsgBox("File " & strDrivePathNameExt & " opened.")
Else
MsgBox("File " & strDrivePathNameExt & " does not exist.")
End If
MsgBox("Here3")
End Sub
End Class