Laurent Crivello
Laurent Crivello

Reputation: 3931

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.

Upvotes: 2

Views: 329

Answers (2)

Julian Mann
Julian Mann

Reputation: 6466

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.

Upvotes: 2

Laurent Crivello
Laurent Crivello

Reputation: 3931

Found it:

int value;
MObject thisObj = thisMObject();
MFnDependencyNode dgNode( thisObj );
dgNode.findPlug("myAttribute").getValue(value);

Upvotes: 0

Related Questions