Reactor doesn't react............

Discussion in 'AutoCAD' started by rewilson, Feb 28, 2004.

  1. rewilson

    rewilson Guest

    Everything I do, I need help. I'm trying to fire a lisp called dtend which runs a short macro on a beginclose event. It exports drawing data to an excel spreadsheet. I have little or no luck designing reactors, but gave it a try. Here's the reactor:

    ;; callback at beginclose event
    (defun reactor:DTEnd (reactor info) (DTEnd))


    ;; make the reactor once at loading
    (or dwg_reactor
    (setq dwg_reactor
    (vlr-dwg-reactor
    ;; we do not need any other type of lisp data here, so a little string message will be fine
    "DTEnd cleaner reactor"
    '(:)vlr-beginclose . reactor:DTEnd)))))

    Could someone take a look at it please and give me some input?TIA
     
    rewilson, Feb 28, 2004
    #1
  2. rewilson

    ECCAD Guest

    rewilson,
    do you have the 'reactors' loaded ?

    (progn
    (vl-load-com)
    (vl-load-reactors)
    )
    ;
    also, cap the "C" in:
    '(:)vlr-beginClose . reactor:DTEnd)))))

    Bob
     
    ECCAD, Feb 29, 2004
    #2
  3. Bob,

    Protected symbols are not case sensitive.

    Command: !:vlr-beginclose
    :VLR-beginClose

    Command: !:vlr-beginClose
    :VLR-beginClose


    Command: !subst
    #<SUBR @02877230 SUBST>

    Command: !SUBST
    #<SUBR @02877230 SUBST>

    Command: !sUbst
    #<SUBR @02877230 SUBST>
     
    Jason Piercey, Feb 29, 2004
    #3
  4. rewilson

    Mark Propst Guest

    are there symbols that are case sensitive?
    (setq DIST 24)
    (print dist)
    :)
     
    Mark Propst, Feb 29, 2004
    #4
  5. rewilson

    ECCAD Guest

    Jason,
    Thanx. I didn't realize..
    Bob
     
    ECCAD, Feb 29, 2004
    #5
  6. Of course not, silly me for implying that only
    protected symbols were not case sensitive. :)
     
    Jason Piercey, Feb 29, 2004
    #6
  7. rewilson

    Doug Broad Guest

    Hi Bob,
    Only (vl-load-com) is required (2000+ I believe).

    Rewilson,
    Alert calls are good to use if you aren't sure a reactor
    callback is getting called. Use them until you understand
    what and when everything is happening.

    Your code is too incomplete to form any other conclusion.

    (defun mycallback (args....) (alert "MyCallback"))
     
    Doug Broad, Feb 29, 2004
    #7
  8. rewilson

    rewilson Guest

    Thanks everyone for the reply's. Doug, I did as you suggested and place an alert after the creation of the reactor, and it appears when you open the drawing. I also
    did a search for reactors, and it returns one. But it's not firing the routine at the begin close event. Could you take a look at the code for me? I appreciate the help.
    (vl-load-com)

    (defun reactor:DTEnd (reactor info) (DTEnd))
    ;;;callback at begin close event
    (or dwg_reactor
    (setq dwg_reactor
    (vlr-dwg-reactor
    "DTEnd cleaner reactor"
    '(:)vlr-beginclose . DTEnd)))))


    (vl-acad-defun 'DTEnd)
    ;;Define the function

    (defun DTEnd ()
    ;define function

    (setvar "CMDECHO" 0)
    ;switch off command echo

    (if (findfile "DTbegin.dvb")
    ;if the project file is found
    ;in your AutoCAD search path

    (progn
    ;do the following

    (setvar "FILEDIA" 0)
    ;switch off dialogue boxes

    (command "_vbaload"
    (findfile "DTBegin.dvb"))
    ;load the project file

    (command "-vbarun" "Module2.DrawingEnd")
    ;run the project macro

    (command "_vbaunload" "DTBegin")
    ;unload the file

    (setvar "FILEDIA" 1)
    ;switch dialogues back on

    ) ;progn

    (princ "\nDTBegin.dvb not found")
    ;if project not found, inform the user

    ) ;if

    (setvar "CMDECHO" 1)
    ;switch command echo back on


    (princ)
    (princ)

    (princ))
    ;;;exit quitely
     
    rewilson, Mar 1, 2004
    #8
  9. rewilson

    Doug Broad Guest

    You can't use (command....) inside a reactor.
    Instead use (vla-sendcommand... or something similar.
    You should avoid using (setvar.....) inside a reactor.
    The (princ)'s are probably superfluous for beginclose.

    Start with
    (defun reactor:DTEnd (reactor info) (alert "Closing"))

    and then debug from there, if that works.

    the creation of the reactor, and it appears when you open the drawing. I also
    begin close event. Could you take a look at the code for me? I appreciate the help.
     
    Doug Broad, Mar 1, 2004
    #9
  10. rewilson

    rewilson Guest

    OK Doug..............I'll give it a go. Thanks for tips!
     
    rewilson, Mar 1, 2004
    #10
  11. rewilson

    JamesA Guest

    Doug, you've sparked confusion in a little brain. I thought sendcommand
    should be avoided along with command (i.e. anything calling functions using
    command line). And I use setvar heavily in reactors. Is there a problem
    with this that I should know about? Further enlightenment requested.

    Thanks,

    James
     
    JamesA, Mar 1, 2004
    #11
  12. rewilson

    Doug Broad Guest

    I haven't had any problems with setvar but any reactor
    that uses 'all-documents notification or is contained in
    a separate namespace vlx might not work or might
    operate inconsistently with setvar, since setvar works
    only with the activedocument. Instead (vla-setvariable
    can target a particular variable in a particular document).
    The same thing goes with getvar vs. vla-getvariable.

    If all your reactors are set up locally, then the above
    might not be a problem. In some cases, an elock
    violation can possibly occur, although I haven't noticed
    that being a big problem. That seems to be more of
    a problem with (entmod)

    I don't believe sendcommand is a problem but its been
    so long since I have played with it, I can't be sure. I knew
    that (command... will cause a problem and make the
    reactor not appear to operate. Some kinds of errors
    don't report to the user within reactors. In general,
    any command that would require user interaction should
    definitely be avoided.

    Even more confused now? Life is like that. ;-)
     
    Doug Broad, Mar 1, 2004
    #12
  13. rewilson

    rewilson Guest

    Actually, can't I just use
    (vl-VBARUN "Module2.DrawingEnd") ?
    It seems to work, but I still can't get the reactor to fire.
     
    rewilson, Mar 1, 2004
    #13
  14. rewilson

    Doug Broad Guest

    I'd have to test it myself to find out. In general, I
    try to avoid starting VBA during a close event unless
    it is already running. Are you setting
    this reactor up for all drawings or for just the drawing
    into which it is loaded? To get it to fire, when any
    drawing closes, you need to use the vlr-set-notificaton
    statement.

    Did it fire with just the alert? (dummied form)

    Reactors work quite well in VBA BTW. Perhaps if
    your reactor is merely starting a VBA routine, it might
    as well be implemented in VBA entirely.
     
    Doug Broad, Mar 1, 2004
    #14
  15. rewilson

    rewilson Guest

    I thought that could be done, but didn't know how to do it. Is it still called a beginclose? Can you show me an example?TIA
     
    rewilson, Mar 1, 2004
    #15
  16. rewilson

    Doug Broad Guest

    Paste this into your Thisdrawing

    Private Sub AcadDocument_BeginClose()
    MsgBox "Closing"
    End Sub

    Did you see my questions?


    beginclose? Can you show me an example?TIA
     
    Doug Broad, Mar 1, 2004
    #16
  17. rewilson

    rewilson Guest

    Yes, I saw your questions. But I was on my out of the office for the day, and in my haste didn't answer them. Apologies. I'm setting it up for all open drawings, which causes another headache. I load the macro with a lisp on drawing startup, and run module1.drawingbegin. At drawing close, module2.drawingend runs. It needs to unload the macro when it's finished to avoid the alert when it reloads at the next drawing open. The alert is not a problem, I'd just rather not see it.
    I tried the (alert 'close) on the reactor, and didn't get an alert. I don't know enough about reactors, but I've got one lisp firing on a beginclose event now. Could that be causing the problem? If so, can I fire two seperate routines from the same reactor? Would it need to be persistent to do that
    I'll try the VBA in the morning when get to the office, and let you know. Thanks for all your help.
     
    rewilson, Mar 2, 2004
    #17
  18. rewilson

    Doug Broad Guest

    The problem with LISP reactors is that they are attached to each
    individual drawing. That can be an advantage if you want to do
    something different to each drawing but otherwise makes things more
    complicated.

    1) (alert 'close) would stall the reactor immediately because it would
    cause an error. Alert takes only string arguments. Any error in a
    reactor causes the reactor to appear its not working.

    2) If, with each reactor, you are calling VBA routines, then you should
    write VBA events instead of lisp reactors. There are only a few events
    that are not available to VBA (although none come to mind).

    3) Reactors should always assume they are not working alone and also
    should not assume that they occur in any specific sequence. That is, if
    there are 2 beginclose reactors, then the order is not predictable.

    4)AFAIK, only object reactors can be made persistent.

    5)A program to create a reactor should always check to see that it has
    not already been created. Otherwise, things start happening 2 or more
    times. New reactors don't replace old reactors.

    and in my haste didn't answer them. Apologies. I'm setting it up for all
    open drawings, which causes another headache. I load the macro with a lisp
    on drawing startup, and run module1.drawingbegin. At drawing close,
    module2.drawingend runs. It needs to unload the macro when it's finished to
    avoid the alert when it reloads at the next drawing open. The alert is not a
    problem, I'd just rather not see it.
    don't know enough about reactors, but I've got one lisp firing on a
    beginclose event now. Could that be causing the problem? If so, can I fire
    two seperate routines from the same reactor? Would it need to be persistent
    to do that
    Thanks for all your help.
     
    Doug Broad, Mar 2, 2004
    #18
  19. rewilson

    rewilson Guest

    Doug, you have done well. Doing it from VBA rather than lisp is exactly what I needed. I load the project from the acad2000.lsp, then fire from VBA with a beginopen and also a beginclose event. It works exactly as I had hoped, and I really appreciate all your time,effort and input. Many thanks to you. (I've also learned a ton of stuff)!
     
    rewilson, Mar 2, 2004
    #19
  20. rewilson

    JamesA Guest

    Doug, I also thank you for the extra info. I guess I haven't run into these
    problems as all of my reactors are defined from vlisp reactors and not vba
    events. But I have thought about converting to vba events so I should keep
    these things in mind.

    Thanks again,

    James
     
    JamesA, Mar 2, 2004
    #20
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.