TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on February 28, 2005, 12:09:59 PM

Title: Reactor...
Post by: Andrea on February 28, 2005, 12:09:59 PM
Hi,

I'm trying understand reactor...

does anyone can give me some samples with the

vlr-commandWillStart
vlr-commandEnded
vlr-commandCancelled

??

thanks.
Title: Reactor...
Post by: nivuahc on February 28, 2005, 12:25:43 PM
Sure Andrea, be glad to!

Check out this link (http://theswamp.org/phpBB2/viewtopic.php?t=3267&highlight=reactor). It has quite a bit of really great information about reactors and how they work.
Title: Reactor...
Post by: Andrea on February 28, 2005, 02:58:20 PM
ok...I have made this...

for test..
but the alert box apear 4 times...WHY ???





Code: [Select]
(vl-load-com)

;*******************************************************
(vlr-command-reactor
nil '((:vlr-commandWillStart . startCommand))
)

(defun startCommand (calling-reactor startcommandInfo /)

  ;thecommandstart drgName newname)

(setq thecommandstart (nth 0 startcommandInfo))

(if (= thecommandstart "PLINE")
 (progn
 (alert "The PLINE command was activated")
 (setq thecommandstart NIL)
 )
 (setq thecommandstart NIL)
 )
))


any HELP ??
Title: Reactor...
Post by: Serge J. Gianolla on February 28, 2005, 05:12:52 PM
Tiens, au lieu de te casser la tete; regarde ici
http://www.theswamp.org/phpBB2/viewtopic.php?t=2745&highlight=reactors
Title: Reactor...
Post by: Andrea on February 28, 2005, 07:20:55 PM
Quote from: Serge J. Gianolla
Tiens, au lieu de te casser la tete; regarde ici
http://www.theswamp.org/phpBB2/viewtopic.php?t=2745&highlight=reactors


Serge !!  Bon sens,,  j'étais en train de t'écrire quand j'ai vu ton post..
depuis le temp que j'essai de trouver le pourquoi du comment.....ouf !!
Je ne sais plus comment t'appeler maintenant....

Proffesseur, Maître,....ou tout simplement Dieu !! 8)


un GROS merci....
Title: Reactor...
Post by: nivuahc on February 28, 2005, 07:32:08 PM
Wow, Andrea, that's an awful lot of praise you threw out there!

Should I have answered you in French?
Title: Reactor...
Post by: Serge J. Gianolla on February 28, 2005, 09:38:16 PM
Quote
Should I have answered you in French?

Ne soyons pas chauvin, nivuahc! :D  :lol:
Glad you enjoyed the other link. Reactors are great... when they behave!!! :oops:
Title: Reactor...
Post by: Serge J. Gianolla on February 28, 2005, 09:48:27 PM
Quote
Je ne sais plus comment t'appeler maintenant....

Pas besoin de m'appeler, je viens tout seul. <<Marrant non! :P
Title: Reactor...
Post by: daron on February 28, 2005, 10:06:31 PM
French??? You might try Italian, if you want them to understand it.
Title: Reactor...
Post by: Andrea on March 01, 2005, 09:15:31 AM
Daron,....

ITALIAN
Parlo anche Italiano...e tù ?
in fatto...sono nato a Roma.

 8)


ENGLISH
ok now i've discover something..

The code work only with AutoCAD 2004 and Higher..
In 2002..this code is not reset back the layer..

WHY ?

FRENCH
Je ne sais pas trop pourquoi ce foutu code ne fonctionne pas bien en 2002
il ne retourne pas à la couche précédente.
Title: Reactor...
Post by: SMadsen on March 01, 2005, 09:27:53 AM
Hmmm, maybe I should start writing in Danish?

[sarcasm]But then I would probably not receive any help in an english speaking forum, would I now?[/sarcasm]
Title: Reactor...
Post by: Andrea on March 01, 2005, 09:33:50 AM
ok...maybe to much work than i can't see..

but i have this code..to anable reactor...



Code: [Select]

(defun c:HTz ()
 (if (CC_find_env);;detect if some variable is set
   (progn  
  (SDC_readSfile);;read other variables
  (setq BC1r T11r
           BC1 T11
  );;redefine some variables
  (loadreactortype);;<---HERE LOAD REACTOR NOT WORKING
);;progn
);;if

(command "_DTEXT")
);;end HTz
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun loadreactortype ()
;;(alert "Reactor loaded")
(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-command-reactor nil '((:vlr-commandFailed . failedCommand)))
)



Also i have made tests with alertbox....and the alertbos is shown..
but the reactor is not active..

why ? :cry:  (i'm tired)
Title: Reactor...
Post by: JohnK on March 01, 2005, 09:54:39 AM
Quit using "COMMAND" In reacor apps!
Title: Reactor...
Post by: daron on March 01, 2005, 10:30:20 AM
To add to 7's comment. While it's bad to use command in reactors, it's even worse to use a command line that errors out to user control and doesn't take control back. Autocad needs to have control in order to react.
Title: Reactor...
Post by: SMadsen on March 01, 2005, 10:40:42 AM
Se7en, the COMMAND is not within a callback so it's perfectly legal.

Andrea, the code you posted gives no clue to the problem, except that CC_FIND_ENV probably returns nil so that LOADREACTORTYPE will never be called.

When you get it working, I hope you are aware of the fact that the way it is written, it will add reactors each time C:HTZ is called (which can become very unpleasant).
Title: Reactor...
Post by: JohnK on March 01, 2005, 10:48:59 AM
Quote from: SMadsen
Se7en, the COMMAND is not within a callback so it's perfectly legal.
...
When you get it working, I hope you are aware of the fact that the way it is written, it will add reactors each time C:HTZ is called (which can become very unpleasant).


The point is that you shouldnt use command or setvar in reactor apps at all untill you KNOW how/why/when you can use them. The fact that you can in certin circimstances is irrelevent to (s)he trying to learn reacotors. First they must learn why/what their code is doing before they can start learning the loop holes.
Title: Reactor...
Post by: SMadsen on March 01, 2005, 10:53:02 AM
Aye Sir!

:P
Title: Reactor...
Post by: JohnK on March 01, 2005, 11:12:09 AM
Im sorry if i sounded gruff in my post.

I think it would be best if you use Pseudo code to layout your reactors. Cause then you can see potential disasters.  Creating a reactor everytime a command is called is not a really good idea. ...you have to be carefull when you use reactors. They can get away from ya real fast.
Title: Reactor...
Post by: MP on March 01, 2005, 11:17:52 AM
A sure way to create a house of cards is to use reactors gratuitously. We use them VERY sparingly.
Title: Reactor...
Post by: Andrea on March 01, 2005, 01:34:37 PM
ok...so if i understand...
can i modify the code like this..


(defun c:HTz ()
 (if (and (not var1) (CC_find_env));;detect if some variable is set
   (progn    
  (SDC_readSfile);;read other variables
  (setq BC1r T11r
           BC1 T11
  );;redefine some variables
  (loadreactortype);;<---HERE LOAD REACTOR NOT WORKING
);;progn
);;if

(command "_DTEXT")
);;end HTz
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun loadreactortype ()
(setq var1 T)
;;(alert "Reactor loaded")
(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-command-reactor nil '((:vlr-commandFailed . failedCommand)))
)

But not seam to work... :roll:
Title: Reactor...
Post by: SMadsen on March 01, 2005, 02:44:20 PM
Setting a flag is one way to go about it, yes. If being precarious, which we all tend to be at times, it wouldn't necessarily mean that the reactors were actually created, though.

Personally, I would use the return value from VLR-COMMAND-REACTOR to tell me directly about the success of the function (in this particular case all the return values).
Title: Reactor...
Post by: Andrea on March 01, 2005, 03:27:13 PM
SMaden..

I'm not sure if I really understand...
could you explain a little more ?
Title: Reactor...
Post by: SMadsen on March 01, 2005, 05:00:29 PM
It's pretty much explained in the thread (http://www.theswamp.org/phpBB2/viewtopic.php?p=34629#34629) that Serge linked to. Did you read the comments in the code?
Title: Reactor...
Post by: Andrea on March 02, 2005, 10:28:11 AM
Quote from: SMadsen
It's pretty much explained in the thread (http://www.theswamp.org/phpBB2/viewtopic.php?p=34629#34629) that Serge linked to. Did you read the comments in the code?


Ok.. I've made some modification in my routine...and it work just fine with 2002 and 2004.

thanks all..

Now I need to know how to unload the reactor without closing the drawing..

any idea ?
Title: Reactor...
Post by: Andrea on March 02, 2005, 10:41:56 AM
ok sorry...i just find it !!

(vlr-remove-all) :oops:
Title: Reactor...
Post by: SMadsen on March 02, 2005, 10:55:53 AM
I'm glad you got it working, Andrea.

Just in case you forgot to do this: If you are depending on recreation of the reactor after having killed it and you are maintaining a global variable that points to it then set the global to nil when destroying it.
Code: [Select]

;; if you are doing this to create the reactor:
...
  (if (not *my-reactor*)
    (setq *my-reactor* (vlr-command-reactor .... etc..)
  )
...

;; then do this when destroying it:
...
  (vlr-remove-all)
  (setq *my-reactor* nil)
...


Of course, if you have multiple reactors running, you can also kill the specific one with (vlr-remove *my-reactor*)
Title: Reactor...
Post by: Andrea on March 02, 2005, 09:51:52 PM
thanks SM I appreciate..
Title: Reactor...
Post by: Andrea on March 03, 2005, 05:53:30 PM
I use this...



(vlr-remove-all :vlr-command-reactor)


is this ok ?
Title: Reactor...
Post by: SMadsen on March 03, 2005, 06:10:39 PM
That would be correct if you want to kill all command reactors, yes.