Results 1 to 10 of 10

Thread: BeginOpen Event - need an event that will execute whenever a drawing is opened

  1. #1
    Member
    Join Date
    2006-12
    Posts
    4
    Login to Give a bone
    0

    Default BeginOpen Event - need an event that will execute whenever a drawing is opened

    I looked up the BeginOpen Event with Autocad VBA Help I got the code displayed below. Problem is the Example_AcadApplication_Events sub has to be executed before it will work. I need an event that will execute whenever a drawing is opened (even if ACAD is opened by double clicking a .dwg file.

    Code:
    Public WithEvents acadApp As AcadApplication
    
    Sub Example_AcadApplication_Events()
        ' This example intializes the public variable (ACADApp) which will be used
        ' to intercept AcadApplication Events
        '
        ' The VBA WithEvents statement makes it possible to intercept an generic object
        ' with the events associated with that object.
        '
        ' Before you will be able to trigger any of the AcadApplication events,
        ' you will first need to run this procedure.
        
        ' We could get the application from the ThisDocument object, but that would
        ' require having a drawing open, so we grab it from the system.
        Set acadApp = GetObject(, "AutoCAD.Application.16")
    End Sub
    
    Private Sub ACADApp_BeginOpen(FileName As String)
        ' This example intercepts an Application BeginOpen event.
        '
        ' This event is triggered when a drawing is opened by AutoCAD.
        '
        ' To trigger this example event:
        '     1) Make sure to run the example that initializes
        '     the public variable (named ACADApp) linked to this event.
        '
        '     2) Use AutoCAD to open an existing drawing
    
        ' Use the "FileName" variable to determine which drawing file is being opened
        MsgBox "A drawing is about to be loaded from: " & FileName
    End Sub
    Last edited by jack.ryan; 2007-02-12 at 10:05 PM. Reason: [CODE] tags added

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,737
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    We've had some discussions here on that subject before. There were several options tossed around. But basically, if your code isn't running, you can't expect it to work. When you dc a file in Explorer, acad simply starts with the last profile that was run. At best, you can set up acad so that this code runs on all profiles at startup. Look into using acad.dvb.
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2006-12
    Posts
    4
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    Okay I saw in another post where you recommended using acad.dvb and creating a public sub in a public module called AcadStartup.

    This event fired when it should have but when it got to the line:
    Set acadApp = GetObject(, "AutoCAD.Application.16")

    I got an error ActiveX Component can't create Object.

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,737
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    You shouldn't need that. vba already declares an application object for you, AcadApplication. I also think you may have a misunderstanding on how to utilize events.
    First, add a class module to your project. For this example, Name it MyEvents.cls
    In the declarations section, add a variable "Public WithEvents oApp As AcadDocument"
    Select the dropdown in the upper left and select the oApp object.
    Then, in the drop down in the upper right, select the BeginOpen event to create a signature for the event.
    Now add your MsgBox line.
    Now in the AcadStartup sub, add this line: "Set MyEvents.oApp = AcadApplication"

    This will create an instance of your events class and set its oDoc object to the current application. This will link the apps events to your event handlers.
    Last edited by Ed Jobe; 2007-02-12 at 11:43 PM.
    C:> ED WORKING....

  5. #5
    Member
    Join Date
    2006-12
    Posts
    4
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    Sorry I'm not getting it. I'm just getting started with ACAD VBA but I've done a lot of VBA and VB in other places and I understand the working side of ACAD pretty good. I still don't think I'm a Guru or anything. And the VBA for AutoCAD is not what I'm used to.

    Doing it my way my only problem was that I had to execute the Example_AcadApplication_Events sub before the BeginOpen Event would be recognized.

    Just for grins though I tried it your way and after I created the MyEvents Module the BeginOpen event did not appear in the upper right pulldown.

    Any chance you have some sample code (A .dvb perhaps)?

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,737
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    You have to scrap what you did and follow the steps I gave you in order for event handling to work properly. Attached is acad.dvb.

    I forgot to mention that you have to select the oApp object in the left dropdown first, then the right dropdown will list its methods. I edited my earlier post.
    Attached Files Attached Files
    Last edited by Ed Jobe; 2007-02-13 at 12:00 AM.
    C:> ED WORKING....

  7. #7
    Member
    Join Date
    2006-12
    Posts
    4
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    Many Thanks!!!

    It works now.

    One thing though. It did not execute on the first drawing I opened so I added a Class_Initialize Routine.

    Also I found that at the Begin Open the drawing Database wasn't loaded yet so I changed it to an EndOpen.

    It works great and it's got me past another roadblock.

  8. #8
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    5,737
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    Glad it worked for you.
    C:> ED WORKING....

  9. #9
    Active Member
    Join Date
    2012-11
    Location
    Italy
    Posts
    65
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    @ jack ryan
    Please, could you share your last dvb?
    thank you

  10. #10
    Woo! Hoo! my 1st post
    Join Date
    2014-07
    Posts
    1
    Login to Give a bone
    0

    Default Re: BeginOpen Event - need an event that will execute whenever a drawing is opened

    I have followed these instructions, but I'm having trouble with assigning the AcadApplication object to the oApp class member. It just hangs up AutoCAD as it loads. I've progressively commented out code, and it's specifically the line where oApp is set. Any clues? AutoCDA hangs at "loading acvba.arx" which is where the acad.dvb code gets loaded, and the startup run.

    Paul

Similar Threads

  1. Execute command on DocumentCreated event problem
    By Alexey Nis in forum Dot Net API
    Replies: 2
    Last Post: 2011-05-08, 12:47 PM
  2. ViewActivated Event
    By Phillip_Miller in forum Revit - API
    Replies: 5
    Last Post: 2010-08-04, 10:06 PM
  3. AUGI event
    By george.arq in forum Português - Cafezinho sem CAD
    Replies: 1
    Last Post: 2007-02-23, 11:39 AM
  4. Replies: 4
    Last Post: 2005-01-24, 10:23 PM

Posting Permissions

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