What is a reactor?
A notification method similar to the MFC messaging mechanism is provided in AutoCAD. Used to handle the following situations:
Execute AutoCAD commands, modify system variables, save and exit the graphical editor, or toggle the current work layout space, and so on.
The reactor mechanism is an implementation of the observer pattern, under which there are event notifier and event receivers, which are responsible for receiving events called reactors. Before the reactor can receive messages from the notifier, the reactor must be explicitly added to the notifier's list of reactors (the list of notification objects in observer mode).
Common reactor types:
Edit reactor: Aceditorreactor Solid reactor: Acdbentityreactor Object reactor: Acdbobjectreactor Graphics Database reactor: Acdbdatabasereactor document management reactor: Acapdocmanag Erreactor
According to the basic properties of the reactor, the reactor is divided into a temporary reactor and a permanent reactor.
The staging reactor itself is not a database object, and the developer is responsible for the registration and uninstallation of the staging reactor, which is used to monitor database events, user actions, and other system events while the program is running.
A permanent reactor is a database object, created by the developer and deleted by AutoCAD, which can receive and send messages, can be saved to DWG and DXF files, and will rebuild the permanent reactors when the drawings are loaded. Used to implement an association reaction between objects.
How to use a temporary reactor
Select a suitable class derivation from a series of reactor classes in Arx to implement the relevant function and register the reactor.
Note: The permanent reactors are removed by AutoCAD, and the temporary reactors are the responsibility of the programmer to remove them.
How to use a permanent reactor
1: Derive a new class from Acdbobject and implement the event function you need to use.
2: Instantiate the reactor object.
3: Add the Reactor object to the database and store it (typically stored in a container)
4: Add the Reactor object through the Addpersistentreactor function to the notifier's list of reactors. This function needs to use the ID of the reactor object.
In addition, you need to use the Objectarx class declaration macro to create a class descriptor object for it
If you do not use the OBJECTARX macro, the class description of the parent class will be inherited when the custom class is saved, and the identity will be lost when it is read out of the file.
Principles of Reactor use
1: Do not rely on the order of activation
In addition to successive relationships like Commandwillstart and commandended, you cannot rely on other orders because the order of notifications changes when new notifications are introduced or when existing notifications are reordered.
2: Do not rely on the order of inter-notification operations
For a reactor, received an action notification of the A object, followed by the operation of the B object notification, this does not guarantee that the A object is before the B object operation.
3: Do not use any user interaction functions in the notification callback function
Do not invoke any functions that interact with the user (similar to operations such as getting points)
OBJECTARX reactor overview [reprint]