0

I have a Maya MEL script, which inserts some nodes. The evaluation seems to be deferred until the script finishes. I guess this comes from the pipeline evaluating when the shape is requested by the renderer, so the dirty propagation starts.

Now I want to run commands if the inserted node calculated a certain output like this:

$node = `insertMyNode`;
dgdirty ($node+".outputAttr");
if(`getAttr ($node+".outputAttr")` == 1) {
    print("true");
} else {
    print("false");
}

This always prints false. When I insert the node and then run getAttr ($node+".outputAttr") in the MEL editor, the node is computed and I get 1.

I tried dgeval as well and it didn't work either. I think in principle neither dgeval nor dgdirty should be needed but getAttr should start the dirty propagation. But it always returns the default value of the node, not the evaluated one.

dgdirty $node works for me, but I still would rather only dirty the output I am using (and if possible automatically, not with a command which is documented to be for debugging purposeses), so the node does not need to recompute all outputs.

myNode has defined and inputMesh parameter which affects an output bool outputAttr value using attributeAffects in its C++ code. the insertMyNode command connects an input mesh. It is correct that the node is not computed without a connection to an output plug, but when reading the plug it should be computed. When I open the node editor and hover over the output plug, the node is computed correctly. I would expect getAttr to do the same in the example code above.

allo
  • 3,955
  • 8
  • 40
  • 71

1 Answers1

1

The dirty propagation usually works if you are dirtying input attributes and request output attributes. To it seems you are dirtying an input attribute and try to get the same input attribute. Usually in a node this is coded with "affects" like: affects(attrA, attrB). and if attrB is requested, the compute() method is called. So I suppose it could work better if you try to get an output attribute.

haggi krey
  • 1,885
  • 1
  • 7
  • 9
  • No, I am dirtying an output attribute there. If it would be an input attribute I would not need the node to compute it. ``dgdirty $node`` works for me, but I still would expect ``dgdirty`` to work on the attribute and ``getAttr`` to dirty the output plug and trigger a computation even without ``dgdirty`` which is documented as command for debugging. – allo Jan 10 '18 at 16:09
  • Ah, yes you are right. Of course the output attribute is marke as dirty. Maybe the attribute itself does not trigger a recalculation if it is dirty. Could be possible that another output attribute does the trigger which would explain why it works if you are dirtying the whole node. – haggi krey Jan 10 '18 at 18:05
  • It should trigger the recomputation (``attributeAffects`` is used for a connected input attribute to affect the output attribute). Maybe the DG changes are not evaluated instantly as well? The C++ ``MPxCommand`` does run ``dgMod.doIt()`` after connecting an input mesh to the input attribute of the node. Is the dgMod delayed while the script is running? – allo Jan 11 '18 at 10:20
  • @allo regerdless you need to mark a input dirty and change it, otherwise it will just compute to the same value every time. If no inputs are dirty then the node will just use the cached value. – joojaa Jan 14 '18 at 21:57
  • input or output? ```insertMyNode``` creates a node, which connects to a input mesh and results in a bool output. I want to read the bool output, which should dirty the output plug, evaluate the node which computes properties of the mesh and then writes the wanted value to its output plug. This works fine, when this is the only part of the script. When I run other stuff afterwards, the evaluation is delayed until the script finished, when just using ``getAttr`` or ``dgdirty`` on the out plug. ``dgdirty`` on the node works, but probably just because it circumvents maya's dependency system – allo Jan 15 '18 at 09:07