Tuesday, February 9, 2010

Introduction to Reactors

Introduction to Reactors

Before the release of AutoCAD 14.01 and the introduction of Visual LISP, having an AutoCAD entity contact an AutoLISP application when an event occurred was nothing more than a pipe dream shared by almost all AutoLISP programmers at one time or another. With the introduction of Visual LISP this pipe dream has become a reality that is accomplished by using reactors. A reactor is an object that is attached to an AutoCAD drawing entity for the express purposes of having AutoCAD contact an application when a specified event occurs. Suppose that an application is created that generates a gear train based on the design parameters supplied by the user. If it is critical for the gear train to be modified as a whole, then by using a reactor AutoCAD notifies the gear train application and takes the appropriate action when the user modifies the part.

Recall from Chapter 7 that an AutoLISP expression or a group of expressions can be associated with either a tile or an entire dialog box. This type of expression (called an action expression) is dormant until the user performs an action; then information regarding this action is returned to the action expression in the form of a callback. Reactors use the same technology to communicate with an application. The application is executed through a callback function. Callback functions associated with reactors are like other functions used in creating AutoLISP programs. The function becomes a callback function once it has been attached to a reactor event.

No comments:

Post a Comment