Search code examples
c++apinodesmaya

How to transmit MPxData to the compute function of Maya


I have a Maya api (in c++) that is defining an MPxNode, and some main code which is instancing this MPxNode.

How can I pass data to the MPxNode so that the data is accessible from the compute method ? From main code:

myMpxObj=dagMod.createNode("myMpxNode");

In MyMPxNode:

MStatus myMpxNode::compute( const MPlug& plug, MDataBlock& block )
{
// How to get here values from the main part ?
    return MS::kUnknownParameter;
}

Thanks.


Solution

  • When you want to get values inside the compute function of a MpxNode, the more efficient way is to get a MDataHandle to your attribute in the MDataBlock.

    findPlug() is slower but necessary in situations where you don't have access to the datablock such as in the doit() method of a command plugin or draw() in a locator.

    MStatus myMpxNode::compute( const MPlug& plug, MDataBlock& block )
    {
        if (plug != myOutPlug) return MS::kUnknownParameter;
    
        int value = block.inputValue(myAttribute).asInt();
        // set output
        return MS::kSuccess;
    }
    

    Here's the dependency node example from the docs.