execute mnl only on autocad startup?

Discussion in 'AutoCAD' started by Kathrin Bombrowski, Apr 7, 2004.

  1. looks like I've build a nice deathtrap. However, maybe someone has an idea?

    I have a mnl file loaded with my mnu which does:
    - load my vlx
    - define some commands
    - set some variables

    Recently it became necessary to set several options with every autocad
    startup, so I included the following line in the mnl:

    (vl-vbarun "gb_AO.dvb!M_Startup.GB_startup")

    Normally this works without problems.

    Now I've got a vba program which exports objects on certain layers using
    wblock. Dependent on user's choice either one drawing or a bunch of drawings
    are created and at last opened.
    The problem: If more than one drawing are opened, only the last one is
    opened completely, the others are locking up whilst executing the startup
    macro and cannot be closed afterwards ("AutoCAD can't close drawing because
    a command is still active...")

    Can I achieve the mnl to be executed only on Autocad startup?
    Or is there a possibility to execute a vba macro only once in a autocad
    session?

    TIA,
    Kathrin
     
    Kathrin Bombrowski, Apr 7, 2004
    #1
  2. Kathrin Bombrowski

    Ed Jobe Guest

    Create a project and save it in a file called acad.dvb. In a public module,
    create a sub called AcadStartup and put your code there. I posted one a week
    or so ago that you can download which toggles caps lock. you can use that to
    start with.
     
    Ed Jobe, Apr 7, 2004
    #2
  3. Thanks for the suggestion, Ed.
    If I use "common" files like acad.dvb or acad.lsp I'll have to make sure
    that they are not used by one of the various 3rd party applications we have
    in use, and this for 160 machines.
    So I would prefer a solution where I'm completely independent from such
    commonly used files.
     
    Kathrin Bombrowski, Apr 7, 2004
    #3
  4. Kathrin Bombrowski

    Wayne Craig Guest

    Kathrin,

    This is a shot in the dark, but maybe if you try something like the
    following in the .MNL file, the reentry could be avoided.

    (vl-load-com)
    (if (= gbHasInitialized 'nil)
    (progn
    (vl-vbarun "gb_AO.dvb!M_Startup.GB_startup") ;DO YOUR STUFF HERE!
    (setq gbHasInitialized T) ;Set a flag to show that your stuff has been
    done!
    (vl-propagate 'gbHasInitialized ) ;Propagate the value to all drawings
    ) ;_end of progn
    ) ;_end of if

    Wayne
     
    Wayne Craig, Apr 7, 2004
    #4
  5. Kathrin Bombrowski

    Wayne Craig Guest

    Kathrin,

    On second thought, this order may be better:

    (vl-load-com)
    (if (= gbHasInitialized 'nil)
    (progn
    (setq gbHasInitialized T) ;Set a flag to show that your stuff has been
    done!
    (vl-propagate 'gbHasInitialized ) ;Propagate the value to all drawings
    (vl-vbarun "gb_AO.dvb!M_Startup.GB_startup") ;DO YOUR STUFF HERE!
    ) ;_end of progn
    ) ;_end of if

    Wayne
     
    Wayne Craig, Apr 7, 2004
    #5
  6. Use one of AutoCAD's USER variables and test it for a value. In your DVB
    Startup, have it set the variable after it runs. Would look something like:

    (if(=(getvar"USERS1")"RUN")
    (vl-vbarun "gb_AO.dvb!M_Startup.GB_startup"))
     
    Mike Tuersley, Apr 7, 2004
    #6
  7. Kathrin Bombrowski

    Ed Jobe Guest

    You might try using acad.lsp and appending your code to the (s::startup)
    function. By appending, no matter what others have done, yours still gets
    run. Try this:

    ;;; Written by: Vladimir Nesterovsky

    (defun PlugIntoStartup (MyFunc) ; "to be called with quoted function name"
    (eval (list 'defun
    'S::StartUp
    ()
    (if S::StartUp
    (list (list 'quote S::StartUp))
    )
    (list MyFunc)
    )
    )
    )

    ;;; Usage: (PlugIntoStartup 'MyDoOpen)
    ;;;
    ;;; where MyDoOpen is your startup code:
    ;;; (defun MyDoOpen ()
    ;;; (defun c:mtext() (c:settxt))
    ;;; (defun c:text() (c:settxt))
    ;;; (defun c:dtext() (c:settxt))
    ;;; (command "._undefine" "mtext" "._undefine" "text" "._undefine" "dtext")
    ;;; (princ)
    ;;; )
     
    Ed Jobe, Apr 7, 2004
    #7
  8. Kathrin Bombrowski

    Ed Jobe Guest

    Also, if you are worried about moving code to 160 machines, most cad mgrs
    have a utility for copying files to the clients. For example, I have an
    Access db on the network that startup functions look to. It has a table for
    that lists users and the last time they updated and a table listing the
    updates/date. Now, when I want to do an update, all I do is change the date
    of the update, if the users update is older than the update's date, a
    program is launched to copy the files. You could do it without the db, but
    the db allows me to see where everyone's at.
     
    Ed Jobe, Apr 7, 2004
    #8
  9. Wayne,
    your solution looks closest to what I want, but I can't bring it to work.
    The thing is, when opening a new drawing the mnl is executed first and then
    the vl-propagate works. Very annoying.
     
    Kathrin Bombrowski, Apr 7, 2004
    #9
  10. But aren't user variables only valid within the drawing they were set?
     
    Kathrin Bombrowski, Apr 7, 2004
    #10
  11. Kathrin Bombrowski

    Ed Jobe Guest

    True, and the string vars are not saved at all. That's why I suggest
    S::Startup in acad.lisp.
     
    Ed Jobe, Apr 7, 2004
    #11
  12. Kathrin Bombrowski

    Ed Jobe Guest

    You know what, I misinformed you. S::Startup runs on each new dwg, don't
    know what I was thinking. You simply want to append to the acad.lsp file.
    Don't replace the file, just append to it. You could do it with vba and the
    Write function when you Open a text file for Append. Then the next time they
    start acad, your code will be loaded.
     
    Ed Jobe, Apr 7, 2004
    #12
  13. Thanks Ed,
    the PlugIntoStartup thing works great.
    Though I'd rather avoid acad.lsp, it seems to be the only solution for my
    problem.
    Many thanx also for your suggestion regarding the update db. It's a great
    idea and I'll deal with it as soon as I can find the time.

    greetings from Germany,
    Kathrin
     
    Kathrin Bombrowski, Apr 7, 2004
    #13
  14. This is what help says, too. Remember, my intention was a routine which runs
    only on acad startup.
    What I completely dont understand (maybe because its late night here) is,
    why does it work for me then?
    I have the acad.lsp with a "hollow" S::Startup and in the .mnl I append my
    startup macro using the PlugIntoStartup function. And it runs definitely not
    on each new dwg.

    Kathrin
     
    Kathrin Bombrowski, Apr 8, 2004
    #14
  15. I think what is happening is you have got Acad.lsp set to load only on startup and if I am correct you are appending to this. Therefore if you had Acad.lsp set to load with every drawing it would run in every drawing. It sounds like it works for you and you just needed to know why so I hope that clarifies it.
    Regards - Nathan
     
    Nathan Taylor, Apr 8, 2004
    #15
  16. ACADLSPASDOC

    is the system variable you should read about.

    Also, look for LISPINIT system variable
     
    Jorge Jimenez, Apr 8, 2004
    #16
  17. You can set LISP variables that have application-level
    scope using (vl-bb-set), and read them with (vl-bb-ref).

    Hence:

    (defun AppInit ()
    (if (not (vl-bb-ref 'zzz:done))
    (progn
    (vl-bb-set 'zzz:done t)
    (RunOnce)
    )
    )
    )

    (defun RunOnce ()
    ;; Code here will run only once per session
    )


    Then, from some place (code executed at startup), just
    call the (AppInit). You can call that any number of
    times, but the (RunOnce) function is called only once,
    the first time AppInit is called.



    AcadX for AutoCAD 2004 Beta 1
    http://mysite.verizon.net/~vze2vjds/acadx/AcadX16.zip
     
    Tony Tanzillo, Apr 8, 2004
    #17
  18. YEAAAHH, thats the solution I was looking for. Wasn't aware of the blackbord
    namespace.
    Many thanks, Tony!

    Kathrin
     
    Kathrin Bombrowski, Apr 8, 2004
    #18
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.