Loading VBA app upon opening first document

Discussion in 'AutoCAD' started by Allen Johnson, Aug 10, 2004.

  1. I use the following code to load a VBA application (AddButtons) upon startup:

    Private Sub AcadDocument_Activate()
    On Error Resume Next
    If Documents.Count = 1 Then AddButtons
    SBBUCSFollow.SetCurrentState
    If Err.Number > 0 Then AddButtons: Err.Clear
    End Sub

    The macro is called from a .mnl file:

    (setq VBAPath "F:\\ACAD Shared\\vba\\")
    (vl-vbaload (strcat VBAPath "SBB-Hilight-UCSFollow.dvb"))


    It works if I close all documents within AutoCAD and reopen another document.
    But it won't run when I start AutoCAD from the desktop icon or clicking on a drawing file name from
    a windows explorer window.

    I don't really want to add it to the Startup Suite, because of the number of machines I'd need to
    manually add it too.

    Any ideas?
     
    Allen Johnson, Aug 10, 2004
    #1
  2. Allen,

    Since you are using the document-level Activate event, I would load via
    Acad.lsp. There is no need to _load_ it in each drawing (which is what the
    ..mnl will do). It is also an issue of when the event fires. The initial
    document must already be activated by the time your code loads.

    So I would explicitly call the procedure from Acad.lsp after loading the
    code.

    --
    R. Robert Bell


    I use the following code to load a VBA application (AddButtons) upon
    startup:

    Private Sub AcadDocument_Activate()
    On Error Resume Next
    If Documents.Count = 1 Then AddButtons
    SBBUCSFollow.SetCurrentState
    If Err.Number > 0 Then AddButtons: Err.Clear
    End Sub

    The macro is called from a .mnl file:

    (setq VBAPath "F:\\ACAD Shared\\vba\\")
    (vl-vbaload (strcat VBAPath "SBB-Hilight-UCSFollow.dvb"))


    It works if I close all documents within AutoCAD and reopen another
    document.
    But it won't run when I start AutoCAD from the desktop icon or clicking on a
    drawing file name from
    a windows explorer window.

    I don't really want to add it to the Startup Suite, because of the number of
    machines I'd need to
    manually add it too.

    Any ideas?
     
    R. Robert Bell, Aug 10, 2004
    #2
  3. In addition to Robert's suggestion, you can do it with straight vba.
    Despite being well seasoned in lisp, I dislike mixing my programming
    languages so:

    1. Create an ACAD.RX file - it is an ASCII textfile with one line ==>
    acvba.arx This automatically will start vba when AutoCAD loads

    2. Create an ACAD.DVB file. In it, you need to add a public sub named
    ACADStartup. Any code within this sub will run automatically whenever
    AutoCAD first starts.


    then either
    3A . Copy/paste your code into the ACAD.DVB so it'll be there

    or

    3B. Using the app object, load the dvb

    The ACAD.DVB and ACAD.RX files need to be within AutoCAD's support file
    paths. You can use multiples of each, but only the first found will be
    used.

    In the ACAD.DVB file, you can add your event programming, too - but you
    won't need any for the operation you are describing. If you did, you should
    be using the EndCommand event and checking to see if the command ending is
    NEW, QNEW or OPEN. The Activate also fires when you have multiple files
    open and toggle between them.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 10, 2004
    #3
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.