Remove Layer Reactor

Discussion in 'AutoCAD' started by Gary Fowler, Mar 1, 2005.

  1. Gary Fowler

    Gary Fowler Guest

    Is my ARCH:CleanLayerReactor the best way to remove the reactor?

    (defun ARCH:CleanLayerReactor ()
    (setq *commandReactor* nil
    *DrawingReactor* nil)
    (mapcar 'vlr-remove-all ':)VLR-Command-Reactor :VLR-Editor-reactor))
    (princ "\n* Remove Layer Reactor completed *\n")
    (princ))

    Gary








    Code:
    (defun ARCH:LAYERREACTORUNLOADER  ()
    (defun ARCH:CleanLayerReactor  ()
    (setq *commandReactor* nil
    *DrawingReactor* nil)
    (mapcar 'vlr-remove-all '(:VLR-Command-Reactor :VLR-Editor-reactor))
    (princ "\n*      Remove Layer Reactor completed        *\n")
    (princ))
    (ARCH:SETLREAMODE "Off")
    (ARCH:CleanLayerReactor))
    
    (defun ARCH:VLR_COMMAND  (/ result)
    (ARCH:DIALOG_SETUP)
    (ARCH:DOSLIBLOADER)
    (setq Result (ARCH:WARNING-5
    "Layer Reactor"
    "     This will automatically switch the Active Layer if
    the\n"
    "     reactor command is recognized. If the Layer does
    not\n"
    "     exist it wiil be created with Color, Linetype, and\n"
    "     Plottable setting.\n\n" "     Do you want to
    continue?"))
    (defun VLR_COMMAND-KEY  ()
    (ARCH:SETLREAMODE "On")
    (ARCH:LAYERREACTORLOADER)
    (princ))
    (cond ((= 0 Result) (VLR_COMMAND-KEY))
    ((= 1 Result) (progn (setq layreactor nil) (ARCH:CANCEL))))
    (princ))
    
    ;;; VLR_COMMAND.lsp courtesy Peter Jamtgaard 2003
    
    ;;; Vlr Command is a function that will switch the active layer in a
    drawing.
    ;;; The reactor checks the command that is starting and if it recognizes it
    ;;; it will switch to a specified layer. If the layer doesn't exist it will
    ;;; create it with the color, linetype, and plottable setting provided.
    ;;; To load and run this program add the lines (load
    "vlr_command")(c:vlr_command)
    ;;; to your acaddoc.lsp or another autoloading lisp routine.
    
    (defun VLR_COMMAND-IT ()
    (vl-load-com)
    (vlr-command-reactor nil '((:vlr-commandWillStart . startCommand)))
    (vlr-command-reactor nil '((:vlr-commandEnded . endCommand)))
    (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand)))
    (vlr-editor-reactor nil '((:vlr-commandwillstart . ARCH:COM1)))
    )
    (princ "\n*** ------ Layer Reactor Activated. ------ ***")
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun ARCH:COM1 (CALL CALLBACK / COMLAYLST)
    ;;; List of corrusponding      commands layers  color linetype     plottable
    (setq COMLAYLST
    (list (list "DIMANGULAR" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMBASELINE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMCENTER" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMCONTINUE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMDIAMETER" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMLINEAR" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMORDINATE" "A-DIMS" 30 "continuous" :vlax-true)
    (list "DIMRADIUS" "A-DIMS" 30 "continuous" :vlax-true)
    (list "QDIM" "A-DIMS" 30 "continuous" :vlax-true)
    
    (list "LEADER" "A-NOTE" 2 "continuous" :vlax-true)
    (list "QLEADER" "A-NOTE" 2 "continuous" :vlax-true)
    
    (list "DTEXT" "A-NOTE" 2 "continuous" :vlax-true)
    (list "MTEXT" "A-NOTE" 2 "continuous" :vlax-true)
    ;;(list "TEXT" "A-NOTE" 2 "continuous" :vlax-true)
    
    ;;(list "BHATCH" "A-PATT" 9 "continuous" :vlax-true)
    ;;(list "HATCH" "A-PATT" 9 "continuous" :vlax-true)
    
    (list "POINT" "X-PNTS" 4 "continuous" :vlax-true)
    
    (list "XLINE" "X-LINE" 8 "continuous" :vlax-true)
    (list "XREF" "0-XREF" 7 "continuous" :vlax-true)
    )
    )
    (foreach
    N COMLAYLST
    (if (= (strcase (car CALLBACK)) (strcase (car N)))
    (progn
    (make_layers
    (cadr N)
    (caddr N)
    (cadddr N)
    (car (cddddr N))
    )
    (setq n1 n)
    (vla-put-activelayer
    (vla-get-activedocument
    (vlax-get-acad-object)
    )
    (vlax-ename->vla-object
    (tblobjname "LAYER" (cadr N))
    )
    )
    )
    )
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Make layers using activeX
    (defun MAKE_LAYERS (LAY_NAM COLOR LTYPE PLOTL / LAYOBJ LAYSOBJ LTYPESOBJ)
    (setq CDWGOBJ (vla-get-activedocument
    (vlax-get-acad-object)
    )
    LAYSOBJ (vla-get-layers CDWGOBJ)
    )
    (if (not (tblobjname "layer" LAY_NAM))
    (vl-catch-all-error-p
    (vl-catch-all-apply 'vla-add (list LAYSOBJ LAY_NAM))
    )
    )
    (setq LAYOBJ (vla-item LAYSOBJ LAY_NAM))
    (if (not (tblobjname "ltype" LTYPE))
    (progn
    (setq LTYPESOBJ (vla-get-linetypes CDWGOBJ))
    (vla-load LTYPESOBJ LTYPE (findfile "acad.lin"))
    (vlax-release-object LTYPESOBJ)
    )
    )
    (vla-put-layeron LAYOBJ :vlax-true)
    (if (/= (strcase (vla-get-name LAYOBJ)) (strcase (getvar "clayer")))
    (vla-put-freeze LAYOBJ :vlax-false)
    )
    (vla-put-lock LAYOBJ :vlax-false)
    (vla-put-color LAYOBJ COLOR)
    (vla-put-linetype LAYOBJ LTYPE)
    (vla-put-plottable LAYOBJ PLOTL)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;Kenny Ramage @ afralisp.com
    (defun startCommand (calling-reactor
    startcommandInfo
    /
    thecommandstart
    )
    (setq OldLayer (getvar "CLAYER"))
    (setq OldLayern OldLayer)
    
    ;;(vlr-editor-reactor nil '((:vlr-commandwillstart . ARCH:COM1)))
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun endCommand (calling-reactor
    endcommandInfo
    /
    thecommandend
    )
    (setq thecommandend (nth 0 endcommandInfo))
    (cond
    ((= thecommandend "DIMANGULAR") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMBASELINE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMCENTER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMCONTINUE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMDIAMETER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMLINEAR") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMORDINATE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "DIMRADIUS") (setvar "CLAYER" OldLayer))
    ((= thecommandend "QDIM") (setvar "CLAYER" OldLayer))
    
    ((= thecommandend "LEADER") (setvar "CLAYER" OldLayer))
    ((= thecommandend "QLEADER") (setvar "CLAYER" OldLayer))
    
    ((= thecommandend "DTEXT") (setvar "CLAYER" OldLayer))
    ((= thecommandend "MTEXT") (setvar "CLAYER" OldLayer))
    ;;((= thecommandend "TEXT") (setvar "CLAYER" OldLayer))
    
    ;;((= thecommandend "BHATCH") (setvar "CLAYER" OldLayer))
    ;;((= thecommandend "HATCH") (setvar "CLAYER" OldLayer))
    
    ((= thecommandend "POINT") (setvar "CLAYER" OldLayer))
    
    ((= thecommandend "XLINE") (setvar "CLAYER" OldLayer))
    ((= thecommandend "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun cancelCommand (calling-reactor
    cancelcommandInfo
    /
    thecommandcancel
    )
    (setq thecommandcancel (nth 0 cancelcommandInfo))
    (cond
    ((= thecommandcancel "DIMANGULAR") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMBASELINE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMCENTER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMCONTINUE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMDIAMETER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMLINEAR") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMORDINATE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "DIMRADIUS") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "QDIM") (setvar "CLAYER" OldLayer))
    
    ((= thecommandcancel "LEADER") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "QLEADER") (setvar "CLAYER" OldLayer))
    
    ((= thecommandcancel "DTEXT") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "MTEXT") (setvar "CLAYER" OldLayer))
    ;;((= thecommandcancel "TEXT") (setvar "CLAYER" OldLayer))
    
    ;;((= thecommandcancel "BHATCH") (setvar "CLAYER" OldLayer))
    ;;((= thecommandcancel "HATCH") (setvar "CLAYER" OldLayer))
    
    ((= thecommandcancel "POINT") (setvar "CLAYER" OldLayer))
    
    ((= thecommandcancel "XLINE") (setvar "CLAYER" OldLayer))
    ((= thecommandcancel "XREF") (setvar "CLAYER" OldLayer))
    )
    )
    
     
    Gary Fowler, Mar 1, 2005
    #1
  2. If this is intended to run before closing the drawing session use:

    (vlr-remove-all)
     
    Luis Esquivel, Mar 2, 2005
    #2
  3. Gary Fowler

    Jürg Menzi Guest

    Hi Luis
    Can be dangerous to remove *all* reactors. Suppose you've more than one
    application running. They are using DocManager reactors with
    ':VLR-documentToBeDestroyed' event to close for example an open database
    connection. The first application closes the database, the rest can't
    because all reactors are removed...
    For a possible solution visit my homepage -> Free Stuff and search for
    'AcadDoc.lsp' (Reactor sample).

    Cheers
     
    Jürg Menzi, Mar 2, 2005
    #3
  4. Gary Fowler

    Gary Fowler Guest

    Thanks Luis, but I should have explained better.

    Correct Jürg, I have other reactors running....like
    James Buzbee's Double Click Reactor running also.
    I will check out your sample reactor.

    For removing all of the running reactors I use the following:

    Code:
    ;;;  Description: This is a general utility function used for cleaning
    ;;;               up reactors. It can be used during debugging, as
    ;;;               well as cleaning up any open reactors before a
    ;;;               drawing is closed.
    ;;;  This file is from the Garden Path tutorial....Util.lsp file
    (defun ARCH:CleanReactorsit  ()
    (setq *commandReactor* nil
    *DrawingReactor* nil)
    (mapcar 'vlr-remove-all
    '(:VLR-AcDb-reactor :VLR-Editor-reactor :VLR-Linker-reactor
    :VLR-Object-reactor
    :VLR-Command-Reactor :VLR-DeepClone-Reactor
    :VLR-DocManager-Reactor
    :VLR-DWG-Reactor :VLR-DXF-Reactor :VLR-Editor-reactor
    :VLR-Insert-Reactor
    :VLR-Linker-Reactor :VLR-Lisp-Reactor :VLR-Miscellaneous-Reactor
    :VLR-Mouse-Reactor :VLR-Object-Reactor :VLR-SysVar-Reactor
    :VLR-Toolbar-Reactor
    :VLR-Undo-Reactor :VLR-Wblock-Reactor :VLR-Window-Reactor
    :VLR-XREF-Reactor))
    (princ "\n*       Remove All Reactors completed        *\n")
    (princ))
    (defun ARCH:CleanReactors  ()
    (setq Result (ARCH:WARNING-5
    "Clean Reactors"
    "     This will Remove and UnLoad All Reactors from Arch
    Program.\n"
    "     \n\n" "     [ Yes ]\t  to continue on...\n" "     [
    No ]\t  to cancel."
    ""))
    (cond ((= 0 Result) (ARCH:CleanReactorsit))
    ((= 1 Result)
    (princ "\n*** ///////// Program  CANCELLED ///////// ***")))
    (princ))
    
    Gary
     
    Gary Fowler, Mar 2, 2005
    #4
  5. thank you Juerg,

    have not been in that condition, I have use basically all reactors type and
    no problema.... will try to run some specific tests....
     
    Luis Esquivel, Mar 2, 2005
    #5
  6. Gary Fowler

    Jürg Menzi Guest

    You're always welcome...¦-)

    Cheers
     
    Jürg Menzi, Mar 2, 2005
    #6
  7. Gary Fowler

    Gary Fowler Guest

    Can you give me some more hints about your comments for other functions
    and other command....I'm still lost.

    Gary

    Code:
    ; - CommandEnded notifications
    (defun VxCommandEndedCallbacks (Rea Arg)
    (VxDoCmdEndedStuff Arg)
    ;;; other functions...
    
    ; - DocToBeDestroyed notification
    (defun VxDocToBeDestroyedCallbacks (Rea Arg)
    ;;; other functions...
    
    ; - Command ended function
    (defun VxDoCmdEndedStuff (Arg / CurCmd CurEnt CurSet FltLst LayNme)
    ;;; other command ended dependent stuff...
    
     
    Gary Fowler, Mar 2, 2005
    #7
  8. Jürg,

    I forgot to mention that all my reactors run inside always on a separate
    protected namespace and (vlr-remove-all) will be safe, since won't create
    any collateral damages.

    Most of the normal reactors implementations are handle in my opinion by
    removing all.

    Database connection can be an specific use and must be handle separatly....
    as you mention.

    Regards.
     
    Luis Esquivel, Mar 2, 2005
    #8
  9. Gary Fowler

    Jürg Menzi Guest

    Hi Gary
    The meaning of:
    ;;; other functions...
    ;;; other command ended dependent stuff...
    is to show where to add other functions/stuff. This has nothing to do with
    the sample function itself.

    Cheers
     
    Jürg Menzi, Mar 2, 2005
    #9
  10. Gary Fowler

    Gary Fowler Guest

    Thanks Jürg and Luis for your help.


     
    Gary Fowler, Mar 2, 2005
    #10
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.