Executing compute on MPxNode without output?

Executing compute on MPxNode without output?

Anonymous
Not applicable
1,139 Views
2 Replies
Message 1 of 3

Executing compute on MPxNode without output?

Anonymous
Not applicable

Hi there.

 

I'm trying to write a DG node with MPxNode as base class.

My node does not have an output attribute but lots of dynamic input attributes.

Because the node does not have output there is no other node that could request an update, so the compute function is never called.

Is there some way to trigger compute for nodes without (connected) output attributes?

 

My node does not have output because it does not affect the scene in any way. It only passes node data to an outside system. But it's really helpful for it to be part of the DG evaluation.

 

The node tree has to end somewhere, right? So it must be possible to write nodes without output (leaf nodes) that still compute something...

 

Thanks.

0 Likes
Accepted solutions (1)
1,140 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Accepted solution

You may create some dummy attribute of any kind, integer for example. 

MStatus YourMPxNode::initialize()
{
    MFnNumericAttribute nAttr;
    attrTrigger = nAttr.create("trigger", "tg", MFnNumericData::kInt, 0);
    nAttr.setStorable(false);
    nAttr.setKeyable(false);
    nAttr.setHidden  (true);
...
}

and make it dependent on all of your input attributes

MStatus YourMPxNode::initialize()
{
   ....
  attributeAffects(atrr1, attrTrigger);
  attributeAffects(attr2, attrTrigger);
}

then if you want to trigger ::compute you need to get the plug of your trigger attribute and request the value

MFnDependencyNode dFn(yourNode);
MPlug triggerPlug = dFn.findPlug("trigger");
if(!triggerPlug.isNull())
    triggerPlug.getValue(i);

 

 

Message 3 of 3

Anonymous
Not applicable

Thank you for your answer.

 


@Anonymous wrote:
...
then if you want to trigger ::compute you need to get the plug of your trigger attribute and request the value

 

MFnDependencyNode dFn(yourNode);
MPlug triggerPlug = dFn.findPlug("trigger");
if(!triggerPlug.isNull())
    triggerPlug.getValue(i);

 

 


 

Where would I do that though? I mean triggering the compute function by requesting the trigger.

Inside the node itself somewhere?

Or would I need to write a script that periodically requests the trigger attribute?

The problem I have, is that there just is no other node or code that would request the output of the node.

 

What I did now is create this trigger attribute and connect it to an input attribute on the same node.

This way "somebody" (the node itself) requests the output of the node, so that compute gets triggered.

Is it a good idea to do it like this? Seems to work fine...

 

0 Likes