You create a reactor that links a callback function to an event.
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:
For example, the following statement 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 a command is issued, whether at the AutoCAD Command prompt, from a user interface element, 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 reactor construction function’s reference topic or can be obtained using vlr-reaction-names. For example, to find the list of possible events for a DWG reactor, you can use the following statement:
(vlr-reaction-names :VLR-DWG-Reactor) (:VLR-beginDwgOpen :VLR-endDwgOpen :VLR-dwgFileOpened :VLR-databaseConstructed :VLR-databaseToBeDestroyed :VLR-beginSave :VLR-saveComplete :VLR-beginClose)