Working with Reactors in Multiple Namespaces

AutoCAD AutoLISP & Visual LISP

 
Working with Reactors in Multiple Namespaces
 
 
 

The current implementation of AutoLISP supports working in one drawing document at a time. Some AutoCAD APIs, such as ObjectARX and VBA, do support the ability of an application to work simultaneously in multiple documents. As a result, an application may modify an open drawing that is not currently active. This is not supported in AutoLISP. (Note that a VLX may run in a separate-namespace from the document it is loaded from, but it is still associated with that document and cannot manipulate objects in another document.)

AutoLISP does provide limited support for reactor callback functions executing in a document that is not active. By default, a reactor callback function will execute only if a notification event occurs when the document it was defined in is the active document. You can alter this behavior using the vlr-set-notification function.

To specify that a reactor should execute its callback function even if the document it was defined in is not active (for example, if an application in another namespace triggers an event), issue the following function call:

(vlr-set-notification reactor-object 'all-documents)

To modify a reactor so it only executes its callback function if an event occurs when the document it was defined in is active, issue the following:

(vlr-set-notification reactor-object 'active-document-only)

The vlr-set-notification function returns the specified reactor object. For example, the following sequence of commands defines a reactor and sets it to respond to events whether or not its associated document is active:

_$ (setq circleReactor
(vlr-object-reactor (list myCircle)
      "Circle Reactor"
'((:vlr-modified . print-radius))))
    
#<VLR-Object-Reactor>
_$ (vlr-set-notification
circleReactor 'all-documents)
#<VLR-Object-Reactor>

To determine the notification setting of a reactor, use the vlr-notification function. For example:

_$ (vlr-notification
circleReactor)
all-documents

The vlr-set-notification function affects only the specified reactor. All reactors are created with the default notification set to active-document-only.

WarningIf you choose to set a reactor to execute its callback function even if triggered when its document is not active, the callback function should do nothing other than set and read AutoLISP variables. Any other action may cause system instability.