Clean Reactor on close

Discussion in 'AutoCAD' started by Rad_Cadder, Jan 21, 2005.

  1. Rad_Cadder

    Rad_Cadder Guest

    I have a reactor setup to fire when "PLOT" is invoked, the problem is it fires one additional time for each drawing I open and plot.
    I would like to setup a reactor cleanup to run at close of drawing.
    Any ideas on how to get this to work would be appreciated.

    (defun CLEANR ()
    (mapcar 'vlr-remove-all
    ':)VLR-Linker-Reactor
    :VLR-Editor-Reactor
    :VLR-AcDb-Reactor
    :VLR-DocManager-Reactor
    :VLR-Command-Reactor
    :VLR-Lisp-Reactor
    :VLR-DXF-Reactor
    :VLR-DWG-Reactor
    :VLR-Insert-Reactor
    :VLR-Wblock-Reactor
    :VLR-SysVar-Reactor
    :VLR-DeepClone-Reactor
    :VLR-XREF-Reactor
    :VLR-Undo-Reactor
    :VLR-Window-Reactor
    :VLR-Toolbar-Reactor
    :VLR-Mouse-Reactor
    :VLR-Miscellaneous-Reactor
    :VLR-Object-Reactor
    )
    )
    )
     
    Rad_Cadder, Jan 21, 2005
    #1
  2. Rad_Cadder

    Jürg Menzi Guest

    HI Rad_Cadder schrieb:

    May you will check this code snippet how to manage reactors:
    Code:
    ; From AcadDoc.lsp:
    ;
    ; - Initialize ActiveX support
    (vl-load-com)
    ;
    ; - Reactors ------------------------------------------------------------------
    ;
    ; - If not set, initialize DocManager-Reactor
    (or Me:ReaDma
    (setq Me:ReaDma (VLR-DocManager-Reactor
    nil
    '(
    (:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
    )
    )
    )
    )
    ; - If not set, initialize Command-Reactor
    (or Me:ReaCom
    (setq Me:ReaCom (VLR-Command-Reactor
    nil
    '(
    (:VLR-commandWillStart . MeCommandWillStartCallbacks)
    (:VLR-commandEnded . MeCommandEndedCallbacks)
    (:VLR-commandCancelled . MeCommandCancelledCallbacks)
    (:VLR-commandFailed . MeCommandFailedCallbacks)
    )
    )
    )
    )
    ;
    ; - Notifications -------------------------------------------------------------
    ;
    ; - CommandWillStart notifications
    (defun MeCommandWillStartCallbacks (Rea Arg)
    (MeDoCmdWillStartStuff Arg)
    ;other functions...
    (princ)
    )
    ; - CommandEnded notifications
    (defun MeCommandEndedCallbacks (Rea Arg)
    (MeDoCmdEndedStuff Arg)
    ;other functions...
    (princ)
    )
    ; - CommandCancelled notifications
    (defun MeCommandCancelledCallbacks (Rea Arg)
    (MeDoCmdCancelledStuff Arg)
    ;other functions...
    (princ)
    )
    ; - CommandFailed notifications
    (defun MeCommandFailedCallbacks (Rea Arg)
    (MeDoCmdCancelledStuff Arg)
    ;other functions...
    (princ)
    )
    ; - DocToBeDestroyed notifications
    (defun MeDocToBeDestroyedCallbacks (Rea Arg)
    ;other functions...
    (MeDoCloseStuff)
    (princ)
    )
    ;
    ; - Subs ----------------------------------------------------------------------
    ;
    ; - Command will start function
    (defun MeDoCmdWillStartStuff (Arg / CurCmd)
    (setq CurCmd (strcase (car Arg)))
    (cond
    ((wcmatch CurCmd "*PLOT")
    (DoYourPlotStuffOnCommandStart)
    )
    ;other command dependent functions
    )
    (princ)
    )
    ; - Command ended function
    (defun MeDoCmdEndedStuff (Arg / CurCmd)
    (setq CurCmd (strcase (car Arg)))
    (cond
    ((wcmatch CurCmd "*PLOT")
    (DoYourPlotStuffOnCommandEnded)
    )
    ;other command dependent functions
    )
    (princ)
    )
    ; - Command cancelled function
    (defun MeDoCmdCancelledStuff (Arg / CurCmd)
    (setq CurCmd (strcase (car Arg)))
    (cond
    ((wcmatch CurCmd "*PLOT")
    (DoYourPlotStuffOnCommandCancelled)
    )
    ;other command dependent functions
    )
    (princ)
    )
    ; - Reactor cleanup function
    (defun MeDoCloseStuff ( / VarLst)
    (setq VarLst (MeGetReaVars))
    (mapcar 'VLR-remove (mapcar 'eval VarLst))
    (mapcar '(lambda (l) (set l nil)) VarLst)
    (princ)
    )
    ; - Collect global reactor variables
    (defun MeGetReaVars ( / RetVal)
    (foreach memb (atoms-family 1)
    (if (wcmatch (strcase memb) "ME:REA*")
    (setq RetVal (cons memb RetVal))
    )
    )
    (mapcar 'read RetVal)
    )
    
    Cheers
     
    Jürg Menzi, Jan 21, 2005
    #2
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.