Reputation: 175
Using the attributeAffects
function two attributes of a Maya node can be linked. For example an input attribute, x
can be linked to an output attribute, y
. This means that when x
is changed, Maya will run a compute()
callback function on the given node, to calculate y
.
However, as far as I can tell, only attributes on the node itself can connected like this, from inside a plugin.
In my plugin I extend an MPxLocator
, and make the output attribute, out
. I want to do the following:
# replace <...> with transform node name.
attributeAffects(CustomNode.out, <custom node's tranform node>.translateX)
attributeAffects(CustomNode.out, <custom node's tranform node>.translateZ)
I can't find any docs on how to do this at all! Has anyone done it / know how? There is a way to hack this by doing the following in the script editor (python):
import maya.cmds as cmds
# Creates CustomNode1, which is linked to transform1 in the DG.
cmds.createNode("CustomNode")
cmds.connectAttr("transform1.translateX", "CustomNode.out")
cmds.connectAttr("transform1.translateZ", "CustomNode.out")
Upvotes: 3
Views: 4305
Reputation: 4434
A node by design should not know of other nodes. That is if the node has some data it needs then that data needs to be internal, or connected in when created or by the user. This is that causes Maya to be efficient. Its not that Maya actually enforces this but neglecting this design idea will make you very unhappy, because you fight Maya all the time (plus its more, extremely error prone, code to maintain).
So this leaves you with 2 options:
Those are your only sane options. But if you really must you can also do what you ask but then you will be making your own event monitoring on top of the free performance optimizing one Maya supplies. Its a bit of extra code and much more debugging on your part, and it will be in all ways inferior.
PS: the reason why your hack works is that Maya evaluates the connections the opposite way they are made, so if you make the output dirty and Maya is asked to evaluate the output then Maya will fire compute
*Just like time, if you make a attribute named time of time type then Maya will connect it for you without asking and showing, unless you connect it to something else. Shading is mostly based on these connections.
Upvotes: 4