Sender Receiver
_______________ _______________
| | | |
| outputData o-------->o inputData |
| | | |
--->o value | | value o--->
| | | |
|_______________| |_______________|
Here's a working example of how to pass a custom C++ instance as attributes between nodes in Maya, using MPxData.
- See MyData below.
import os
import sys
import cmdx
from maya import cmds
cmds.loadPlugin("MyData")
sender = cmdx.createNode("mySender")
receiver = cmdx.createNode("myReceiver")
sender["outputData"] >> receiver["inputData"]
sender["value"] = 5
assert receiver["value"] == 5, "The plug-in didn't work!"
Tested with Maya 2020, but is expected to run from 2011+.
References
git clone https://gist.github.com/f2d520af4dea5bc7b07576e02d544c65.git MyData
cd MyData
mkdir build
cd build
export DEVKIT_LOCATION=/path/to/devkit
cmake .. -GNinja
cmake --build .
When would you want to use MPxData? Why not stick with the built-in types for integers, floats, matrices.. you name it?
You tell me! Sometimes, there's data between two nodes you'd like to share that can't (or shouldn't) be serialised to plain data. Like pointers or heavy data structures not suited or relevant for plugs. For example, if you're writing a physics solver, you'll have plenty of state relevant to a simulation and not-so-much to Maya. Not until the simulation is complete and can be translated into matrices.
Why did you make this example?
Because at the time of this writing the Maya documentation has two examples of how to use MPxData, one is 6,000+ lines and the other is a command rather than a node. I spent a long time decrypting the apiMesh example which features not only use of MPxData but tons and tons of other unrealted features and boiled it down into this one example, for both my future self and for you.