See the top rated post in this thread. Click here

Results 1 to 2 of 2

Thread: How to wait for AutoCAD to be ready?

  1. #1
    Login to Give a bone
    0

    Default How to wait for AutoCAD to be ready?

    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
    Last edited by Ed Jobe; 2019-06-07 at 02:13 PM. Reason: Added CODE tags

  2. #2
    Member
    Join Date
    2009-04
    Posts
    13
    Login to Give a bone
    1

    Default Re: How to wait for AutoCAD to be ready?

    You may want to provide some description on why you want to open a drawing when your add-in DLL is loaded (just remember, you may configure AutoCAD to load it on start-up, but it can also be loaded after AutoCAD started). IMO, opening a drawing in IExtensionApplication.Initialize() is not a good idea, even the DLL is designed to ONLY work against certain drawing. I'd never do it.

    Having said that, you can add an event handler in Initialize() to handle Application.Idle event. That is, when loading your DLL, AutoCAD is obviously busy until the loading is done. As soon as the loading is done (and possible other activities AutoCAD may perform on startup, such as loading menus, AutoCAD will fire event Idle. So, you can place your opening file code in that event handler, and you also probably want to unhook the event handler there.

    Again, while this is doable, you really need to be careful. At least, in the event handler you would have code to check the conditions why/which drawing you want to open after the DLL loading is done.

Similar Threads

  1. How to place beams on multiple floors. But wait, it's not that simple!
    By ppirtle in forum Revit Structure - General
    Replies: 4
    Last Post: 2009-06-08, 06:09 PM
  2. This is a good thing....can't wait!!!
    By dellis in forum DV - The 3rd Dimension
    Replies: 0
    Last Post: 2008-10-30, 08:32 PM
  3. How long do you wait for Support Requests?
    By Andre Baros in forum Revit Architecture - General
    Replies: 16
    Last Post: 2008-04-28, 08:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •