0

Can I use a MProgressWindow inside MPxNode::compute method? My plug-in implementation doesn't reserve MProgressWindow even when it is not being used by another process.

MStatus Node::compute(const MPlug & plug, MDataBlock & data) {
    if (!MProgressWindow::reserve())
        return MS::kFailure;

    MProgressWindow::setTitle(this->typeName);
    MProgressWindow::setInterruptable(true);
    MProgressWindow::setProgressRange(0, 100);
    MProgressWindow::setProgressStatus("Initializing: 0%");
    MProgressWindow::setProgress(0);

    MProgressWindow::startProgress();

    // Some expensive operation.
    // If the user presses ESC key, this ends the progress window and returns failure.

    MProgressWindow::endProgress();

    return MS::kSuccess;
}

Note: When the node is deleted, MProgressWindow is displayed (strange behavior).

I appreciate any help.

Danilo
  • 175
  • 1
  • 11
  • [Maya documentation](https://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_Dependency_graph_plugins_Compute_methods_htm) clearly state that in a node's compute() you should not modify anything else than the node's output attributes. So obviously UI operations that modify things not related to a node will be the source of weird bugs. – arkan May 19 '22 at 12:46

1 Answers1

1

Prior to Maya 2016 plugin code runs in the same thread as Maya's UI. This means that whenever your plugin is doing anything Maya's UI is frozen.

In your compute() the MProgressWindow calls are queuing up a bunch of UI actions but they won't be processed until after compute() returns and the thread can hand control back to the UI.

From Maya 2016 onward it gets more complicated. Whether your plugin code runs in the same thread as Maya's UI depends upon the Evaluation Manager and node type settings.

Try using MComputation instead of MProgressWindow. I haven't tried MComputation from within a compute() method so it may not work, but its design is at least better suited to that usage.

mayaknife
  • 302
  • 1
  • 8
  • Ran into a similar problem and tried MComputation, it doesn't work as well. Doing UI stuff in a compute() method is an architectural mistake anyways ^^ – arkan May 19 '22 at 02:16