The Node Event System available in 3ds Max 2009 and higher lets you define a scripted function that is triggered in response to any of various node-related scene events. The events map one-to-one with the event methods of class INodeEventCallback in the 3ds Max SDK. For detailed information on each, read the methods comments for class INodeEventCallback in maxsdk\include\ISceneEventManager.h
The Node Event System is similar to the General Event Callback Mechanism. It operates as a layer over the General Event Callback system, but also receives some node messages which the older system cannot handle, like geometry, topology and mapping changes. This system will also catch events which happen as a result of undo/redo, while the older system sometimes would not.
Thus, if you wish to catch nodes-related events and changes to nodes, the Node Event System is your best option.
<callbackItem>NodeEventCallback [mouseUp:<bool>] [delay:<integer>] \ [enabled:<bool>] \ [callbackBegin:<fn>] [all:<fn>] \ [added:<fn>] [deleted:<fn>] \ [linkChanged:<fn>] [layerChanged:<fn>]\ [groupChanged:<fn>] [hierarchyOtherEvent:<fn>] \ [modelStructured:<fn>] [geometryChanged:<fn>] \ [topologyChanged:<fn>] [mappingChanged:<fn>] \ [extentionChannelChanged:<fn>] [modelOtherEvent:<fn>] \ [materialStructured:<fn>] [materialOtherEvent:<fn>] \ [controllerStructured:<fn>] [controllerOtherEvent:<fn>] \ [nameChanged:<fn>] \ [wireColorChanged:<fn>] [renderPropertiesChanged:<fn>] \ [displayPropertiesChanged:<fn>] [userPropertiesChanged:<fn>] \ [propertiesOtherEvent:<fn>] \ [subobjectSelectionChanged:<fn>] [selectionChanged:<fn>] \ [hideChanged:<fn>] [freezeChanged:<fn>] \ [displayOtherEvent:<fn>] [callbackEnd:<fn>]
The example script below prints a message to the MAXScript Listener when any message is received by registering a function to the optional keyword argument all:
The script also displays a message box when the linkChanged: or layerChanged: event occurs, that is, whenever one node is linked or unlinked from another node, or moved to a different layer.
When the NodeEventCallback() constructor is called, an instance of the class is created and returned as the result of the call.
To release this instance and thus remove the callback, the value of the variable holding the handler to the instance has to be set to undefined and the garbage collector must be called to reclaim the memory and effectively destroy the callback.
If the optional keyword argument mouseUp: is set to true , the callback will only be triggered when the mouse button is released.
When the optional keyword argument delay: is supplied (as time in milliseconds), the callback is only triggered if the given time passes with no events, that is, only after the system is idle for the specified time.
One or more of the other optional keyword arguments can be supplied with pre-defined MAXScript Functions to be executed if a callback of the specified type is found in the message received by the Node Event System.
IMPORTANT: |
The callback functions always take two parameters: the first is the event name that triggered the function call, the second is a list of node AnimHandles. The GetAnimByHandle() method must be used to get the node itself. If the specified function does not expect two arguments, an error will be thrown. For example, if the function ObjFn is passed but it does not provide any arguments, the error will look like From the text of the error one could incorrectly assume that the function was correct and the callback was wrong, but this is not the case. The callback always passes the two arguments, but if the function is unable to accept them, the error message simply reflects that fact as it has no knowledge what called the function and why it passed two parameters to it. |
When a callback is triggered, messages for all queued events will be sent in one batch.
The callbackBegin: message indicates the start of a batch, while callbackEnd: indicates the end of a batch.
Registering functions using these two optional keyword arguments lets you get notification of the beginning and the end of a single message batch.
The supplied function will be called whenever ANY of the node-related messages listed below has been received.
The supplied function will be called whenever a node has been added to the scene.
The supplied function will be called whenever a node has been deleted from the scene.
The supplied function will be called whenever the node is linked to or unlinked from another node.
The supplied function will be called whenever the node has moved to another layer.
The supplied function will be called whenever the node has been added or removed from a group.
The supplied function will be called whenever the node's hierarchy has been changed in some other way.
The supplied function will be called whenever the model's structure has been modified.
The supplied function will be called whenever the geometry of the node has changed, for example a vertex has been moved.
The supplied function will be called whenever the topology of the node's geometry has changed, for example an edge has been added or removed.
The supplied function will be called whenever the mapping of the node's geometry has changed, for example UV coordinates have been assigned or modified.
The supplied function will be called whenever the a non-mapping channel of the node has been changed, for example Vertex Alpha, Soft-Selection and so on.
The supplied function will be called whenever the node's model has been changed in some other way.
The supplied function will be called whenever a material has been added or removed from the node.
The supplied function will be called whenever the node's material has been changed.
The supplied function will be called whenever a controller has been assigned or removed to a SubAnim track of the node.
The supplied function will be called whenever a node's controller has been changed in another way.
The supplied function will be called whenever the name of the node has been changed.
The supplied function will be called whenever the wireframe color of the node has been changed.
The supplied function will be called whenever the Render Properties of the node has been changed, including Renderable, Visible To Camera, Visible To Reflections and so on.
The supplied function will be called whenever a display property of the node has been changed, for example "Display As Box", "Show Vertex Ticks", "Backface Culling" and so on.
The supplied function will be called whenever the User Properties buffer of the node has been changed.
The supplied function will be called whenever any other properties of a node have been changed.
The supplied function will be called whenever the sub-object selection of a node has changed.
The supplied function will be called whenever the selected state of the node has changed, for example a node has been selected or deselected.