IntelliCAD.net

The IntelliCAD Network

Since Bricscad's lisp engine supports reactors, why not use them? What are reactors? Well they are call back functions that "react" when an event occurs such as a command or a new document is opened. In this example I will setup three reactors and their callback functions. They will react when a command begins, ends, or is canceled by executing their callback functions, that in this example will change the layer setting depending on the intercepted command, then set the layer back to its original state when the command is done. This comes in very handy, if for example you would like all blocks inserted into the drawing to be on the "0" layer, or if you want all dimensions on specific layer...

(defun load__command_reactors ()
 (vl-load-com)
 (if _reactor_start
 (vlr-remove _reactor_start)
 )
 (if _reactor_end
 (vlr-remove _reactor_end)
 )
 (if _reactor_cancel
 (vlr-remove _reactor_cancel)
 )
 (if _reactor_Close
 (vlr-remove _reactor_Close)
 )
 (setq _reactor_start (vlr-command-reactor nil 
 '((:vlr-commandWillStart . start_command)))
 _reactor_end (vlr-command-reactor nil 
 '((:vlr-commandEnded . end_command)))
 _reactor_cancel (vlr-command-reactor nil 
 '((:vlr-commandCancelled . cancel_command)))
 )
 (princ "\nLoading My reactors ")
 )
 ;;;-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-=-==
 (load__command_reactors)
 ;;;-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-=-==
 (defun start_command 
 (calling-reactor start_command_info / the_command_start)
 (setq *Current_Layer_setting* (getvar "CLAYER")
 the_command_start (car start_command_info)
 )
 (cond ;// change the layer
 ((= the_command_start "INSERT")
 (setvar "CLAYER" "0")
 )
 ((= the_command_start "TEXT")
 (setvar "CLAYER" "TEXT")
 )
 ((= the_command_start "MTEXT")
 (setvar "CLAYER" "TEXT")
 )
 ((= the_command_start "DTEXT")
 (setvar "CLAYER" "TEXT")
 )
 ((= the_command_start "QLEADER")
 (setvar "CLAYER" "TEXT")
 )
 ((= the_command_start "DIMALIGNED")
 (setvar "CLAYER" "DIM")
 )
 ((= the_command_start "DIMLINEAR")
 (setvar "CLAYER" "DIM")
 )
 )
 (princ)
 )
 ;;;-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
 (defun end_command 
 (calling-reactor end_command_info / the_command_end)
 (setq the_command_end (car end_command_info))
 (cond ;// set the layer back if the command ended
 ((= the_command_end "INSERT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "TEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "MTEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "DTEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "QLEADER")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "DIMALIGNED")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_end "DIMLINEAR")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 )
 (princ)
 )
 ;;;-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-=-=
 (defun cancel_command 
 (calling-reactor cancel_command_info / the_command_cancel)
 (setq the_command_cancel (car cancel_command_info))
 (cond ;// set the layer back if the command was canceled
 ((= the_command_cancel "INSERT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "TEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "MTEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "DTEXT")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "QLEADER")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "DIMALIGNED")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 ((= the_command_cancel "DIMLINEAR")
 (setvar "CLAYER" *Current_Layer_setting*)
 )
 )
 (princ)
 )
 ;;;-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-=

Tags: Bricscad

Comment

You need to be a member of IntelliCAD.net to add comments!

Join IntelliCAD.net

Vaidas Comment by Vaidas on January 16, 2010 at 1:43pm
Daniel,
This item I reported as SR20900.

CAB,
I'm using object-reactors and for this reason I prefer persistent reactors. Thanks for opinion, hope I'll find a way to redefine reactors on startup.
Daniel Comment by Daniel on January 16, 2010 at 6:34am
"Comment by CAB 8 hours ago Delete Comment Here is another one. Don't have a copy of Bricscad so I can't test it.
http://www.theswamp.org/index.php?topic=22733.msg273953#msg273953
"

Cab
Excellent work as always : )
The routine works just fine on Bricscad V9 & V10
Daniel Comment by Daniel on January 16, 2010 at 6:33am
Vaidas,

You're right! persistent reactors don't seem to survive opening/closing/saving.
have you reported this?
CAB Comment by CAB on January 15, 2010 at 9:36pm
IMO persistent reactors are not the best choice because the lisp if not loaded will not run.
It is beat to add the reactor load to the lisp Startup process & the reactor will be loaded
and activated. Which is the just as good as a persistent reactors. The advantage being that
if you don't want it loaded just take it out of the start process & no problems occur.
CAB Comment by CAB on January 15, 2010 at 9:31pm
Here is another one. Don't have a copy of Bricscad so I can't test it.
http://www.theswamp.org/index.php?topic=22733.msg273953#msg273953
Vaidas Comment by Vaidas on January 15, 2010 at 2:43pm
Hi Daniel,

What about persistent reactors, are you using this option?
From my tests sometimes Bricscad is losing reactors after saving.

Badge

Loading…

© 2010   Created by Deelip Menezes.   Powered by .

Badges  |  Report an Issue  |  Terms of Service

Sign in to chat!