How to clean up Command Reactors?

Discussion in 'AutoCAD' started by Alexander V. Koshman, Dec 30, 2003.

  1. Hello to every living soul here!
    ---------------------------------

    I would ask how I must clean up Command reactors
    in every particular .lsp file correctly?

    Example:
    =========
    1. Create the action reactor:

    (vl-load-com)
    (setq command1-start-rr (VLR-Command-reactor nil '(:)VLR-commandWillStart .
    command1-start))))

    2. Make the action function:

    (defun command1-start ( calling-reactor commandInfo / )
    ...
    ) ; - 'defun'

    3. Create the cleaning reactor:

    (setq close-clean-rr (VLR-DWG-Reactor nil '(:)vlr-BeginClose .
    close-clean))))

    4. Question: What I have to write in cleaning function?

    (defun close-clean ()
    (vlr-remove command1-start-rr)
    (setq command1-start-rr nil)
    (setq command1-start nil)
    ) ; - 'defun'

    And how about the Cleaning reactor itself?
    Do I have to clean it too???


    Thank you in advance!
     
    Alexander V. Koshman, Dec 30, 2003
    #1
  2. Alexander V. Koshman

    John Uhden Guest

    Off the top of my head...
    For only :vlr-command-reactor, use:
    (defun close-clean (Reacctor Info)
    (mapcar 'vlr-remove (mapcar 'cadr (vlr-reactors :vlr-command-reactor)))
    )
    For everything, use:

    (defun close-clean (Reactor Info)
    (vlr-remove-all)
    )
    As to clearing out symbol names, it only matters when in SDI and LISPINIT is set
    to 0.
     
    John Uhden, Dec 30, 2003
    #2
  3. Alexander V. Koshman

    Doug Broad Guest

    John,
    Excellent point about lispinit and sdi.

    Alexander,
    Don't miss another important point about John's
    post. Callback functions, even for cleaning up,
    must have arguments in accordance with the
    specifications in the lisp documentation.

    Unless writing a separate namespace application,
    I prefer not to call (vlr-remove-all) or to use
    the method John' used for cleaning up command
    reactors because I believe each application should
    be responsible for cleaning up after itself. There
    could be more than one beginclose reactors for
    example. There is no guarantee that the other
    beginclose reactors would execute properly if
    one application decided to pre-empt them all.

    I sometimes use (setq reactors (vlr-remove-all))
    when I want to temporarily disable other reactors
    and then add them back with (vlr-add reactors)
    to re-enable them.

    A cleanup reactor can also disable itself while it is
    operating.
     
    Doug Broad, Dec 30, 2003
    #3
  4. Alexander V. Koshman

    John Uhden Guest

    Thanks, Doug, for adding the sage corrections. I had rushed an answer that
    needed more explantion.
     
    John Uhden, Dec 31, 2003
    #4
  5. Thank your both John and Doug!
    ------------------------------------
    Cool! I like MAPCAR more and more!..
    I experimented onece and got an error message trying to remove
    :VLR-Miscellaneous-Reactor with (vlr-remove-all :VLR-Miscellaneous-Reactor)
    when there was no Miscellaneous Reactors active.
    I fear to did a mistake but it seems to me I did some repetition experiments
    and it was so again....Maybe (vlr-remove-all) will be more humane??? ; )
    Thanks God! - it is very little possibly I think, but I can't be sure so
    I have to control this myself. Thank you!

    ---------------------------------
    Yes! I did so but I've simplified my example too much!
    Very nice and simple! ; )
    Glad to hear that, did so already, it's working!
     
    Alexander V. Koshman, Dec 31, 2003
    #5
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.