Lee Mac Posted December 14, 2008 Posted December 14, 2008 I really don't understand Reactors, and, before someone points me there, yes, I have already read the AfraLISP Reactor Tutorials. I was trying to construct a Reactor based on the Layer Setting Reactor as provided on AfraLISP, the reactor would set the current layer to "XREF" whenever an XREF was inserted, then after the insertion, the current layer would revert back to the original. I started to construct the reactor as shown below: ; Xref Layer Director by Lee McDonnell (vl-load-com) (if (not (tblsearch "layer" "XREF")) (progn (setq oldlay (getvar "clayer")) (vl-cmdf "-layer" "m" "XREF" "") (setvar "clayer" oldlay) ) ;_ end progn ) ;_ end if (vlr-xref-reactor nil '((:vlr-beginAttach . startAttach)) ) ;_ end vlr-xref-reactor (vlr-xref-reactor nil '((:vlr-abortAttach . abortAttach)) ) ;_ end vlr-xref-reactor (vlr-xref-reactor nil '((:vlr-endAttach . endAttach)) ) ;_ end vlr-xref-reactor (defun startAttach (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "XREF") (princ) ) ;_ end defun (defun abortAttach () (setvar "clayer" oldlay) (princ) ) ;_ end defun (defun endAttach () (setvar "clayer" oldlay) (princ) ) ;_ end defun But I really do not understand the arguments that one must supply in the LISP programs, for example, in the following reactor, where on earth do the highlighted arguments come from??? ; Layer Director (vl-load-com) (vlr-command-reactor nil '((:vlr-commandWillstart . startCommand)) ) ; end command reactor (vlr-command-reactor nil '((:vlr-commandEnded . endcommand)) ) ; end command reactor (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand)) ) ; end command reactor (defun startCommand ([color=Red][b]calling-reactor startcommandInfo[/b][/color] / thecommandstart) (setq oldlay (getvar "clayer")) (setq thecommandstart (nth 0 [b][color=Red]startcommandInfo[/color][/b])) (cond ((= thecommandstart "TEXT") (setvar "clayer" "TEXT") ) ; end condition 1 ((= thecommandstart "MTEXT") (setvar "clayer" "TEXT") ) ; end condition 2 ((= thecommandstart "DTEXT") (setvar "clayer" "TEXT") ) ; end condition 3 ; --------------------------- ((= thecommandstart "DIMLINEAR") (setvar "clayer" "DIM") ) ; end condition 4 ((= thecommandstart "DIMALIGNED") (setvar "clayer" "DIM") ) ; end condition 5 ((= thecommandstart "DIMRADIUS") (setvar "clayer" "DIM") ) ; end condition 6 ((= thecommandstart "DIMDIAMETER") (setvar "clayer" "DIM") ) ; end condition 7 ((= thecommandstart "DIMANGULAR") (setvar "clayer" "DIM") ) ; end condition 8 ((= thecommandstart "DIMORDINATE") (setvar "clayer" "DIM") ) ; end condition 9 ; --------------------------- ((= thecommandstart "+VPORTS") (setvar "clayer" "DEFPOINTS") ) ; end condition 10 ) ; end cond (princ) ) ; end startcommand (defun endCommand ([b][color=Red]calling-reactor endcommandInfo[/color][/b] / thecommandend) (setq thecommandend (nth 0 [color=Red][b]endcommandInfo[/b][/color])) (cond ((= thecommandend "TEXT") (setvar "clayer" oldlay) ) ; end condition 1 ((= thecommandend "MTEXT") (setvar "clayer" oldlay) ) ; end condition 2 ((= thecommandend "DTEXT") (setvar "clayer" oldlay) ) ; end condition 3 ; --------------------------- ((= thecommandend "DIMLINEAR") (setvar "clayer" oldlay) ) ; end condition 4 ((= thecommandend "DIMALIGNED") (setvar "clayer" oldlay) ) ; end condition 5 ((= thecommandend "DIMRADIUS") (setvar "clayer" oldlay) ) ; end condition 6 ((= thecommandend "DIMDIAMETER") (setvar "clayer" oldlay) ) ; end condition 7 ((= thecommandend "DIMANGULAR") (setvar "clayer" oldlay) ) ; end condition 8 ((= thecommandend "DIMORDINATE") (setvar "clayer" oldlay) ) ; end condition 9 ; --------------------------- ((= thecommandend "+VPORTS") (setvar "clayer" oldlay) ) ; end condition 10 ) ; end cond (princ) ) ; end endCommand (defun cancelCommand ([b][color=Red]calling-reactor cancelcommandInfo[/color][/b] / thecommandcancel) (setq thecommandcancel (nth 0 [color=Red][b]cancelcommandInfo[/b][/color])) (cond ((= thecommandcancel "TEXT") (setvar "clayer" oldlay) ) ; end condition 1 ((= thecommandcancel "MTEXT") (setvar "clayer" oldlay) ) ; end condition 2 ((= thecommandcancel "DTEXT") (setvar "clayer" oldlay) ) ; end condition 3 ; --------------------------- ((= thecommandcancel "DIMLINEAR") (setvar "clayer" oldlay) ) ; end condition 4 ((= thecommandcancel "DIMALIGNED") (setvar "clayer" oldlay) ) ; end condition 5 ((= thecommandcancel "DIMRADIUS") (setvar "clayer" oldlay) ) ; end condition 6 ((= thecommandcancel "DIMDIAMETER") (setvar "clayer" oldlay) ) ; end condition 7 ((= thecommandcancel "DIMANGULAR") (setvar "clayer" oldlay) ) ; end condition 8 ((= thecommandcancel "DIMORDINATE") (setvar "clayer" oldlay) ) ; end condition 9 ; --------------------------- ((= thecommandcancel "+VPORTS") (setvar "clayer" oldlay) ) ; end condition 10 ) ; end cond (princ) ) ; end cancelCommand All help is much appreciated. Quote
Raggi_Thor Posted December 14, 2008 Posted December 14, 2008 I think it´s easier to use VBA if I need reactors. Is that an option? You have the event BeginCommand for example, if CommandName is like XREF then change the layer. Quote
Lee Mac Posted December 14, 2008 Author Posted December 14, 2008 I would really like to stick to LISP - I am relatively new to LISP, but I do not know the first thing about VBA... Plus, that would seem like avoiding a problem - and I would like to understand it. But thanks for your suggestion. Quote
Lee Mac Posted December 16, 2008 Author Posted December 16, 2008 Just bumping the thread up - as its unresolved - again, an unresolved forum would be great Quote
ASMI Posted December 16, 2008 Posted December 16, 2008 Maybe: (vl-load-com) (if(not cmdReactor) (setq cmdReactor (vlr-command-reactor nil '((:vlr-CommandEnded . endXref)) ) ;_ vlr-command-reactor ); end setq ); en if (if(not(tblsearch "layer" "XREF")) (vla-Add (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) "XREF") ); end if (defun endXref (reac arg) (if(= "XATTACH"(car arg)) (vla-put-Layer(vlax-ename->vla-object(entlast)) "XREF") ); end if (princ) ) ;_ end defun Excuse me. I have too little time this week. Quote
Lee Mac Posted December 17, 2008 Author Posted December 17, 2008 Thank you for providing the code ASMI, much appreciated. But would you also be able to explain how you get the highlighted arguments in my first post? Quote
ASMI Posted December 17, 2008 Posted December 17, 2008 Thank you for providing the code ASMI, much appreciated. But would you also be able to explain how you get the highlighted arguments in my first post? This arguments come from reactor. First contains reactor, second contains list of data (refer events table of each type of reactor) You can name it as you want. There is no need three reactors: (vlr-command-reactor nil '((:vlr-commandWillstart . startCommand)) ) ; end command reactor (vlr-command-reactor nil '((:vlr-commandEnded . endcommand)) ) ; end command reactor (vlr-command-reactor nil '((:vlr-commandCancelled . cancelCommand)) ) ; end command reactor you can use one and use check of existance: (if(not cmdReactor) (setq cmdReactor (vlr-command-reactor nil '((:vlr-commandWillstart . startCommand) (:vlr-commandEnded . endcommand) (:vlr-commandCancelled . cancelCommand)) ) ; end command reactor ); end setq ); end if Otherwice you will create new reactors every time you load this file and each reactor will reacts for your event. Quote
ASMI Posted December 17, 2008 Posted December 17, 2008 Check this threads: http://www.cadtutor.net/forum/showthread.php?t=29481 http://www.cadtutor.net/forum/showthread.php?t=27191 http://www.cadtutor.net/forum/showthread.php?t=13146 http://www.cadtutor.net/forum/showthread.php?t=23495&page=3 http://www.cadtutor.net/forum/showthread.php?t=27872 http://www.cadtutor.net/forum/showthread.php?t=5569&page=3 Quote
Lee Mac Posted December 17, 2008 Author Posted December 17, 2008 Excellent, thanks for your help ASMI Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.