Jump to content

Understanding Reactors


NoroZorro

Recommended Posts

Hello,

 

Looking into tutorials, I got stuck on the theme of Reactors. The author provides excellent explanation, but I don't get it.:geek: http://www.afralisp.net/visual-lisp/tutorials/reactors-part-1.php

 

(vl-load-com)

;**************************************************************

;setup and intilise the reactor
(vlr-dwg-reactor "Save Complete" '((:vlr-savecomplete . savedrawinginfo)))

;**************************************************************

(defun saveDrawingInfo (calling-reactor commandInfo / dwgname filesize
                                        reactType reactData reactCall
                                             reactEvent reactCallback)

;get the reactor Object
(setq reactInfo calling-reactor

     ;get the reactor Type
     reactType (vl-symbol-name (vlr-type reactInfo))

     ;get the Application Data
     reactData (vlr-data reactInfo)

     ;get the Callback list
     reactCall (car (vlr-reactions reactInfo))

     ;extract the Event Reactor
     reactEvent (vl-symbol-name (car reactCall))

     ;extract the Callback Function
     reactCallback (vl-symbol-name (cdr reactCall))

);setq

;get the Drawing Name
(setq dwgname (cadr commandInfo)

    ;extract the filesize
    filesize (vl-file-size dwgname)
     
);setq

;display the Drawing Name and Size
(alert (strcat "The file size of " dwgname " is "
       
(itoa filesize) " bytes."))

;Display the Reactor Information
(alert

 (strcat
   "A " "\"" reactType "\"" " named " "\"" reactData "\"" "\n"
   "was triggered by a " "\"" reactEvent "\"" " event call." "\n"
   "Callback Data was passed to the" "\n"
   "\"" reactCallback "\"" " call back function."))

(princ)

);defun

;********************************************************

(princ)

 

 

I will try to formulate question.

 

If i load only defun function savedrawinginfo, the result in visual lisp console SAVEDRAWINGINFO.

 

savedrawinginfo has two arguments (calling-reactor and commandInfo)

 

My rough guess where to get the calling-reactor data is from this line

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

the result in visual lisp console #

 

Now to use the function savedrawinginfo.

(SAVEDRAWINGINFO # commandInfo)

 

I have no clue where we get the data for commandinfo argument. I can find its value from the watch (# "C:\\Users\\the good custumer\\Documents\\Drawing1.dwg"), but that's after saving drawing.

 

As you can see i'm very confused. I tried to look for a simplier explanation of this subject,but i was not able. Please help

Link to comment
Share on other sites

The function "savedrawinginfo" is used by the reactor and the reactor itself should feed the two arguments so the first argument stands for the reactor object itself and the second one is the drawing name as shown in the attached example.

 

By mindful that this sort of reactors is different that command reactor and than object reactors so each one has its own behaviour and attitude.

Link to comment
Share on other sites

Thanks for quick reply. These arguments are passed to "savedrawinginfo" function by reactor

 

'#

(# "C:\\Users\\xxxxx\\Documents\\Drawing1.dwg")

 

1. How can I check the values of these arguments before they are passed?

 

2. Once the function savedrawinginfo is loaded. Why can't I do something (wrong) like this, to see the result of this function

(savedrawinginfo '# (# "C:\\Users\\the xxxxx custumer\\Documents\\Drawing1.dwg"))

Link to comment
Share on other sites

There won't any result unless the related reactor send these information as arguments to the fore-said function to do what it is programmed for.

 

FYI working with reactors is considered a very advanced level and it is not a simple thing to play with easily.

Link to comment
Share on other sites

There won't any result unless the related reactor send these information as arguments to the fore-said function to do what it is programmed for.

 

FYI working with reactors is considered a very advanced level and it is not a simple thing to play with easily.

 

I know, i'm in pain because of it.

 

Am i getting closer?

 

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

---> calling-reactor, '#

 

:vlr-saveComplete

---->commandinfo, (# "C:\\Users\\the xxxxx custumer\\Documents\\Drawing1.dwg") First paramter is the acaddbase object to save at.

Second paramater is a string containing the actual file name used for the save

 

;get the reactor Object
(setq reactInfo calling-reactor

     ;get the reactor Type
     reactType (vl-symbol-name (vlr-type reactInfo))

     ;get the Application Data
     reactData (vlr-data reactInfo)

     ;get the Callback list
     reactCall (car (vlr-reactions reactInfo))

     ;extract the Event Reactor
     reactEvent (vl-symbol-name (car reactCall))

     ;extract the Callback Function
     reactCallback (vl-symbol-name (cdr reactCall))

)

 

How to find out what variables should be set in function?

Link to comment
Share on other sites

(defun saveDrawingInfo (calling-reactor commandInfo / dwgname filesize reactType reactData reactCall reactEvent reactCallback)

 

I try hard to understand, how did the author of this program know that he had to set these variables reactType reactData reactCall reactEvent reactCallback

Link to comment
Share on other sites

Naming variables is up to programmers but it is recommended to name variables to what describes the data that it would be assigned to which would help when they go back to codes for reading or modifying.

 

Have you read THIS before you started the thread?

Link to comment
Share on other sites

Yes I had a look at the link you provided. I don't see in the link that you have to obtain the following information for callback function to work:

;get the reactor Type

;get the Application Data

;get the Callback list

;extract the Event Reactor

;extract the Callback Function

Link to comment
Share on other sites

You can find more functions on the left side hand and they are a bit down the list and what is suit your needs now is the functions that start with vlr-****

Link to comment
Share on other sites

(vl-load-com)

;*******************************************************
(vlr-command-reactor "CheckCommand" '((:vlr-commandEnded . testCommand)))



;*******************************************************
(defun testCommand (calling-reactor endcommandInfo /  thecommandend)

	  

(setq thecommandend (nth 0 endcommandInfo))


 
(princ)
 
);defun

;*********************************************************

(princ)

 

(setq thecommandend (nth 0 endcommandInfo))

 

Please tell me, can i have a list of latest commmands, meaning having nth 1 2 3 or it has to be 0 only

 

Thanks

Link to comment
Share on other sites

1. Do I have only one command in the name of command call?

2. what is the data expected from :vlr-commandEnded ex.(somethingx line)?

Link to comment
Share on other sites

1. Do I have only one command in the name of command call?

As long as you can not run two commands at the same time (transparent command is not included here) so there must be one command name.

2. what is the data expected from :vlr-commandEnded ex.(somethingx line)?

Reactor_object & Arguments (the second item of the arguments data would include the command name and you can retrieve it as I said before with cadr function).

Link to comment
Share on other sites

Thank you Tharwat

It's much more clear how this piece of code works.

 

 

(vl-load-com)

;*******************************************************
(vlr-command-reactor "CheckCommand" '((:vlr-commandEnded . testCommand)))



;*******************************************************
(defun testCommand (calling-reactor endcommandInfo /  thecommandend )

	  

(setq thecommandend (nth 0  endcommandInfo))
(if (= thecommandend "NP")
  (alert (strcat "NoroJan"))
  )

 
(princ)
 
);defun

;*********************************************************

(princ)

 

Reactor_object & Arguments (the second item of the arguments data would include the command name and you can retrieve it as I said before with cadr function)

 

Please correct me

1. Reactor_object is named "calling-reactor" , "endcommandInfo" contains two arguments(the second is command, what's the first?)

 

2. :vlr-commandEnded CAN'T be applied on custom command.

Link to comment
Share on other sites

1. Reactor_object is named "calling-reactor" , "endcommandInfo" contains two arguments(the second is command, what's the first?)

The reactor is not named but it is the object itself.

I am sorry I was wrong with the second issue which is the command name and it is the first element from the argument list so you need to use car function or nth with zero to retrieve the command name as you did before.

2. :vlr-commandEnded CAN'T be applied on custom command.

Yes it is not possible, so if you are indicating to lisp commands, there is a separate reactor for lisp commands and you should be able to find it in the previous link that I posted for you earlier.

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...