Jump to content

Reactors


Lee Mac

Recommended Posts

Hi All,

 

This thread has stemmed from a previous thread posted in which a timer was required on drawings.

 

A suggestion was made to use a reactor so that everytime the user hits "save" the timer would update.

 

I provided a LISP that would create the timer, and everytime the LISP was called, the timer would update:

 

(defun c:timer (/ t1 h1 h1r m1 m1r str)
   (setvar "cmdecho" 0)
   (setq t1 (getvar "tdindwg"))
   (setq t1 (* t1 86400))
   (setq h1 (fix (/ t1 3600)))
   (setq h1r (rem t1 3600))
   (setq m1 (fix (/ h1r 60)))
   (setq m1r (fix (rem h1r 60)))
   (setq str (strcat "Drawing Time: "     
   (itoa h1) "hrs " 
   (itoa m1) "mins "
   (itoa m1r) "secs.")
   )
   (command "MODEMACRO" str)
   (setvar "cmdecho" 1)
   (princ)
)

(c:timer)

But I do not know the first thing about what a reactor is, how it works, and how to create one.

 

If anyone has any information on reactors, I would be grateful for their contribution to this thread. :)

Link to comment
Share on other sites

I keep getting a return of "error - too few arguments" for the following code:

 

(vl-load-com)
(vlr-dwg-reactor "Save Complete" '((:vlr-savecomplete . timer)))

(defun timer (/ t1 h1 h1r m1 m1r str)
   (princ "\nTimer LISP by Lee McDonnell \tType \"RESETTIME\" to Disengage.")
   (setvar "cmdecho" 0)
   (setq t1 (getvar "tdindwg"))
   (setq t1 (* t1 86400))
   (setq h1 (fix (/ t1 3600)))
   (setq h1r (rem t1 3600))
   (setq m1 (fix (/ h1r 60)))
   (setq m1r (fix (rem h1r 60)))
   (setq str (strcat "Drawing Time: "     
   (itoa h1) "hrs " 
   (itoa m1) "mins "
   (itoa m1r) "secs."))
   (command "MODEMACRO" str)
   (setvar "cmdecho" 1)
   (princ)
)

Link to comment
Share on other sites

(vl-load-com)

[color="Blue"](if(not save:reactor)[/color]
       (setq save:reactor
       (vlr-dwg-reactor "Save Complete"
	 '((:vlr-savecomplete . timer))))
 ); end if

(defun timer ([color="#0000ff"]reac args [/color]/ t1 h1 h1r m1 m1r str)
   (princ "\nTimer LISP by Lee McDonnell \tType \"RESETTIME\" to Disengage.")
   (setq t1 (getvar "tdindwg"))
   (setq t1 (* t1 86400))
   (setq h1 (fix (/ t1 3600)))
   (setq h1r (rem t1 3600))
   (setq m1 (fix (/ h1r 60)))
   (setq m1r (fix (rem h1r 60)))
   (setq str (strcat "Drawing Time: "     
   (itoa h1) "hrs " 
   (itoa m1) "mins "
   (itoa m1r) "secs."))
   [color="Red"];;; (command "MODEMACRO" str) Taboo!!! [/color]
   (setvar "MODEMACRO" str)
   (princ)
)

 

1. Check reactor existance to prevent multiple the same reactors.

2. Reaction function requre two (in some reactors three arguments). Inspect it in debug mode :wink:

3. Do not use 'command' or 'vl-cmdf' inside reaction functions.

Link to comment
Share on other sites

ASMI, as usual, you have sorted out my problems -- Thanks :)

 

The LISP works perfectly, but I do have a few questions regarding the use of the reactor.

  1. Why do you set a variable: "save:reactor" - what is this variable used for?
  2. The two arguments: "reac" "args" - where are they used? and why do you use these specific arguments?
  3. Finally, in the construction of the reactor:

(vlr-dwg-reactor "Save Complete" '((:vlr-savecomplete . timer))))

What is the purpose of the "Save Complete" term?

Link to comment
Share on other sites

Hi.

 

1. Why do you set a variable: "save:reactor" - what is this variable used for?

 

For reactor control. For example reactor doubling prevention as in my example, or reactor deletion with:

 

(vlr-remove save:reactor)
(setq save:reactor nil)

 

You can also change reactor data or reaction function and do many other actions.

 

2. The two arguments: "reac" "args" - where are they used? and why do you use these specific arguments?

 

'reac' argument contains reactor, args - event identifier f. e. initial command name in command reactor.

 

3. Finally, in the construction of the reactor:

(vlr-dwg-reactor "Save Complete" '((:vlr-savecomplete . timer))))

 

It can be any autolisp data or NIL. You can retrieve it inside reaction function with 'vlr-data' function.

 

There is independense day and four holydays. Bue till Wednesday.

Link to comment
Share on other sites

  • 8 months later...

Lee,

 

Since you gained more knowledge over the last half year I guessed you might have an answer for this one.

 

Is it possible to write lips for a timer that alerts me if the actual drawing wasn't saved for more than 15 minutes?

 

I believe it has something to do with reactors but they are way out of league for me (that might be incorrect english).

 

Tnx mate.

Link to comment
Share on other sites

Purhaps try the approch that, the next command after the last log, done by a save, will do a auto save.

Link to comment
Share on other sites

No, I really want an "alert" that says "You did not save the current drawing for at least 15 minutes."

There will be an OKE button automatically, but maybe a "save now" button can be added. Its just a thought for it happens that I loose sense of time and in the end a fatal error occurs... We always have the automatic save file, I know, it does every 3 minutes but still... I think it would be nice to be alerted.

Link to comment
Share on other sites

Lee,

 

Since you gained more knowledge over the last half year I guessed you might have an answer for this one.

 

Is it possible to write lips for a timer that alerts me if the actual drawing wasn't saved for more than 15 minutes?

 

I believe it has something to do with reactors but they are way out of league for me (that might be incorrect english).

 

Tnx mate.

 

I think this is possible, but there are other ways to do it - I wrote a LISP that would autosave after x number of commands, or one that would save upon invoking a certain command... just a few other options to consider.

 

PS, your english is great :)

Link to comment
Share on other sites

Just found this one... written a while back, not sure if it worked or not...

http://www.cadtutor.net/forum/showthread.php?t=34497

 

 

This is better:

http://www.cadtutor.net/forum/showthread.php?t=37834

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...