AutoCAD Application Events - EndOpen

Discussion in 'AutoCAD' started by mbabich, Jul 19, 2004.

  1. mbabich

    mbabich Guest

    I have written a macro that I want to run every time I open a drawing. I want to call this macro from the application event - EndOpen. I have followed the suggestions from the help file and it works, but only after i initialize the application event class module which I've been doing manually. I want to initialize the class module when I start AutoCAD, so I placed a small lisp routine to call the initialize sub (via -vbarun) in the acad2004.lsp file which is supposed to load only once. It turns out, that it runs every time a drawing is opened. When I start AutoCAD the initialize macro runs fine. The next drawing I open however hangs. I don't get my crosshairs back. It seems to be stuck in the initialize macro which is being called again because of the lisp routine in the acad2004.lsp file.
    How do I run the initialize event once and only when AutoCAD starts up? I do not want this to run everytime I open a drawing.
    Programming application events can be very powerful, but they don't make it easy to initialize the custom events. For example, the BeginOpen and EndOpen events. In order for those to work, you have to connect your custom events to the application which seems to be a manual step. There should be some way to automatically initialize your custom events when AutoCAD starts.

    I would appreciate any help or insites you could give me.
    Thanks in advance,
    M. Babich
     
    mbabich, Jul 19, 2004
    #1
  2. mbabich

    TomD Guest

    I'm not certain if it would help, but have you looked into the "Startup
    Suite".

    Also, maybe looking into using acad.dvb.

    want to call this macro from the application event - EndOpen. I have
    followed the suggestions from the help file and it works, but only after i
    initialize the application event class module which I've been doing
    manually. I want to initialize the class module when I start AutoCAD, so I
    placed a small lisp routine to call the initialize sub (via -vbarun) in the
    acad2004.lsp file which is supposed to load only once. It turns out, that it
    runs every time a drawing is opened. When I start AutoCAD the initialize
    macro runs fine. The next drawing I open however hangs. I don't get my
    crosshairs back. It seems to be stuck in the initialize macro which is being
    called again because of the lisp routine in the acad2004.lsp file.
    do not want this to run everytime I open a drawing.
    it easy to initialize the custom events. For example, the BeginOpen and
    EndOpen events. In order for those to work, you have to connect your custom
    events to the application which seems to be a manual step. There should be
    some way to automatically initialize your custom events when AutoCAD starts.
     
    TomD, Jul 19, 2004
    #2
  3. This info from the help file should set you in the right direction.

    _____________________________________

    Automatically Load and Execute VBA Projects

    As you build up a number of VBA projects, you can load them automatically each time you run AutoCAD. The macros they contain are immediately available. Additionally, the APPLOAD command provides a Startup Suite option that automatically loads the specified applications.

    acvba.arx — Automatically Load VBA
    You cannot load VBA until an AutoCAD VBA command is issued. If you want to load VBA automatically every time you start AutoCAD include the following line in the acad.rx file:

    acvba.arx


    You can automatically run a macro in the acad.dvb file by naming the macro AcadStartup. Any macro in your acad.dvb file called AcadStartup automatically executes when VBA loads.

    acad.dvb — Automatically Load a VBA Project
    The acad.dvb file is useful if you want to load a specific VBA project that contains macros you want each time you start AutoCAD. Each time you start a new AutoCAD drawing session, AutoCAD searches for the acad.dvb file and loads it.

    If you want a macro in your acad.dvb file to run each time you start a new drawing or open an existing one, add the following code to your acaddoc.lsp file:

    (defun S::STARTUP()
    (command "_-vbarun" "updatetitleblock")
    )
    The project name in the example is updatetitleblock.

    _____________________________________

    Regards - Nathan
     
    Nathan Taylor, Jul 20, 2004
    #3
  4. mbabich

    mbabich Guest

    Nathan,
    Thanks for the help. I gave that a try and of course, it didn't work either. For some reason, the AcadStartup sub doesn't run, not to mention that this sub is located in the ThisDrawing portion of the VBA project acad.dvb. It seems that acad.dvb is never loaded, so I added it to the Startup Suite and it still wouldn't fire the AcadStartup sub.
    From a logical standpoint, the AcadStartup sub wouldn't be executed until a drawing has been loaded because it's located in ThisDrawing. This would be after the event that I'm trying to attach this macro too - EndOpen. I also tried the acad.rx file and Acad told me that VBA had already been loaded. FYI, I'm using Arch. Desktop 2004. I suspect that VBA is loaded differently than straight AutoCAD. This is probably why acad.dvb isn't being fired. I searched the various locations on my HD and the server to see if I could find any other dvb files but couldn't find any that seem to be of the startup variety.
    Again, thanks for your help and if you've got any other suggestions, I would appreciate those as well.

    Mb
     
    mbabich, Jul 20, 2004
    #4
  5. A long shot but remove it from the startup suite and use Acad.rx to load it.

    Regards - Nathan
     
    Nathan Taylor, Jul 21, 2004
    #5
  6. I just went through this. Try this.

    1. Take your vbarun statement out of your Acad2004.Lsp file. The manual
    implies that this is a "reserved" startup file, for AutoCAD use only.

    2. Insert your vbarun statement into a new or existing Acad.Lsp file. This
    should be located in your ACAD support folder. Putting the vbarun statement
    in the S::Startup() function works for me.

    3. Set the following system variables:
    SDI = 0 (Multi Document Interface (MDI) is set)
    ACADLSPASDOC = 0 (default), Acad.Lsp loaded once at AutoCAD startup

    Your VBA will run once immediately after the editor loads the first drawing
    (if you use S::Startup()). There is a very enlightening section of the
    online manual that details the order in which the various startup files are
    run. Search for "Acad.Lsp" & "ACADLSPASDOC".
    --
    John Goodfellow
    irtfnm
    use john at goodfellowassoc dot com


    either. For some reason, the AcadStartup sub doesn't run, not to mention
    that this sub is located in the ThisDrawing portion of the VBA project
    acad.dvb. It seems that acad.dvb is never loaded, so I added it to the
    Startup Suite and it still wouldn't fire the AcadStartup sub.
    a drawing has been loaded because it's located in ThisDrawing. This would be
    after the event that I'm trying to attach this macro too - EndOpen. I also
    tried the acad.rx file and Acad told me that VBA had already been loaded.
    FYI, I'm using Arch. Desktop 2004. I suspect that VBA is loaded differently
    than straight AutoCAD. This is probably why acad.dvb isn't being fired. I
    searched the various locations on my HD and the server to see if I could
    find any other dvb files but couldn't find any that seem to be of the
    startup variety.
    would appreciate those as well.
     
    John Goodfellow, Jul 21, 2004
    #6
  7. mbabich

    mbabich Guest

    WooooHoooo!
    That worked like a charm! Thanks so much John. I owe you one.
    I created an acad.lsp file and entered the following code into it.
    (defun-q S::Startup ()
    (vl-vbaload "u:/Production Admin/DGI Library/VBA/SetStdTxt.dvb")
    (vl-vbarun "InitializeEvents")
    )
    I then closed acad and restarted it - checked to see if the vba project was loaded (which it was) an then opened a file to see if the EndOpen event was fired - and it was!!!

    Thanks again,
    Matt
     
    mbabich, Jul 21, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.