Creating Reactors

AutoCAD AutoLISP & Visual LISP

 
Creating Reactors
 
 
 

You link a callback function to an event when you create a reactor. There is an AutoLISP function for creating each type of reactor. These functions have the same name as the reactor type, minus the leading colon. For example, vlr-acdb-reactor creates a database reactor, vlr-toolbar-reactor creates a toolbar reactor, and so on. Except for object reactors, the reactor creation functions require the following arguments:

  • AutoLISP data to be associated with the Reactor object
  • A list of pairs naming the event and the callback function to be associated with that event (event-name . callback_function)

For example, the following command defines a DWG Editor reactor. The reactor will invoke the saveDrawingInfo function in response to a user issuing a SAVE command:

(vlr-dwg-Reactor nil '((:vlr-saveComplete . saveDrawingInfo)))

In this example, the first argument is nil because there is no application-specific data to attach to this reactor. The second argument is a list consisting of dotted pair lists. Each dotted pair list identifies an event the reactor is to be notified about, and the callback function to be run in response to that event. In this case the reactor is notified of only one event, :vlr-saveComplete.

Editor reactors are notified each time the user issues a command, whether through the AutoCAD command line, a menu, a toolbar, or an AutoLISP program. So, the callback function for this DWG reactor needs to determine precisely what it is responding to. In the current example, save-drawingInfo simply checks for the Save command.

Possible events for each reactor type are listed in the AutoLISP Reference. To find the list of events for a reactor, refer to the entry in the AutoLISP Reference that describes the function used to create the reactor. For example, to find the list of possible events for a DWG reactor, refer to the entry for vlr-DWG-reactor.

All reactor construction functions return a Reactor object.