Maya progressBar and interrupting a script loop

maya2009_120This seems to be a function that is forgotten by many MEL programmers but can save you a lot of headaches.

It is one of those things you might want to implement anywhere in a script you know will do some heavy looping that could take a lot of processing time.

Just add this to your script early on and you are able to interrupt your script by pressing ESC, and a as a bonus you can implement a progress bar for some visual feedback.

global string $gMainProgressBar;
int $maxPBar = 10000;
progressBar -e -bp -ii 1 -max $maxPBar $gMainProgressBar;

for($i=0; $i < $maxPBar; $i++)
{
    if(`progressBar -q -ic $gMainProgressBar`)
    {
        break;
    }

    // here goes you code

    progressBar -e -s 1 $gMainProgressBar; // increases the progress bar
}

progressBar -e -endProgress $gMainProgressBar; // call this when you stop the script or when the script is done

Offcourse, the counter isn’t really necesary, just adding this script without increasing the progressBar alone is enough to prevent you having to force quit Maya and losing your script when your script decides to take hours to finish.

Share

4 thoughts on “Maya progressBar and interrupting a script loop

  1. Hi. Tnks a lot for the tip, I am having an issue here with progress bars.

    When you are just rendering a frame in the renderview, the default maya progress bar show the progress of the render in the help line. Is there a way to execute a script when that progress bar reaches 100%? something like:

    gMainProgressBar = maya.mel.eval(‘$tmp = $gMainProgressBar’)
    prog = cmds.progressBar( gMainProgressBar, q=1, pr=1)

    if prog[0] == 100:
    print “done” // or call any script

    You can tell me in mel, i think i can convert it to python

    Thank you

    • If you need to do something post rendering, you could simply use the postRender and postRenderFrame entries in the Render Options in the render panel.

      You could also create a callback to some of the rendering hooks (a bit more complex to set up though.)

  2. Well, thanks a lot. I did try “post render mel” but the command executes when the render started. But I was not aware of postRenderFrame and it works just fine. Thank you Sir 🙂

  3. Hi again.

    Well, I am trying to remove the caps from the renderView after render. The comon cmds for that works fine in any render. But not in arnold render :/. So I tought that I should “force” it to clear the caps in the renderview using a script after the render.

    The problem is that it works one time, but it ends up not working sometimes or flashing the caps on/off, starnge. Somehow arnold render forces the caps to show, since they use the custom comment feature to print the sampling and render data as caps.

    Is there any other method to remove the caps from the renderview? Like edit the layout that contains the caps. Any hack is welcome.

    By caps i mean captions/renderinfo (rendertime, frame, reender engine, etc), those white letters that are making my life so hard right now 🙂

    If you dont see that its possible, can you tell me a bit more about “You could also create a callback to some of the rendering hooks (a bit more complex to set up though.)”

    Thank you again

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.