Search code examples
maxscript

How to get self node in a scripted object?


I'm writing a plugin helper in maxscript and need to get the node that is the object. Sounds simple right? hah! "this" returns the instance of the plugin class, I think.. might also be the class itself.. who knows, the documentation isn't exactly specific on this.. or anything. I've resorted to guessing what the right combination of words might be (like "this.node" or just "node"), no luck there.

I can spawn a pick dialog and pick the node myself but thats beyond stupid. Any clues?


Solution

  • Generally speaking, you don't want to reference a node for data in an object. If the node depends on the object, and the object depends on the node, you can see how it this would cause a lot of issues. Another issue is if your plugin is instanced. Then 2 nodes point at one object - which one is correct?

    Ideally, you should design your plugin in such a way that it doesn't need a node pointer (ie, create a WSModifier, or work as a utility instead). If you need the nodes transform, then you can get that without a pointer to the node: http://help.autodesk.com/view/3DSMAX/2015/ENU/?guid=__files_GUID_461915FA_31A2_49CE_84AF_2544B782ACA3_htm

    The delegate local variable in a scripted plug-in that creates a scene object does not contain the node itself, but a the BaseObject of that node. As such, you can not access the node level properties of the object being created. An exception to this is the node’s transform, which is exposed to the scripted plug-in through a local variable called nodeTM . This variable is described in the applicable scripted plug-in type topics. 
    

    If your determined to talk directly to the node despite this, then you can get a list of all classes that depend on your class with

    refs.dependents
    

    http://help.autodesk.com/view/3DSMAX/2015/ENU/?guid=__files_GUID_95453E22_A022_4543_B31C_A052CECD3598_htm

    This will get a list of all dependents, including your node. iterate over the list and use the first node found.