Having trouble with progressBar increments

30 views
Skip to first unread message

kiteh

unread,
Oct 18, 2019, 2:56:49 PM10/18/19
to Python Programming for Autodesk Maya
Is it possible to have all the maya commands within a method to be integrated into cmds.progressBar?
I am trying to denote the process rather than just using the waitCursor icon (as it may be deem as the application hanging)

However I am having issues in incrementing the process.

import maya.mel

def anim_baking(startFrame, endFrame):
    gMainProgressBar = maya.mel.eval('$tmp = $gMainProgressBar')
    cmds.progressBar(
        gMainProgressBar,
        edit=True,
        beginProgress=True,
        isInterruptable=True,
        status='Creating the helpers...',
        maxValue=(endFrame-startFrame))

    selections = cmds.ls(sl=True, l=True)
    
    for sel in selections:
        cmds.progressBar(main_progress_bar, edit=True, step=1)

        # create locators
        ...
        # do the constraints
        ...
        # iterate channels and set some attributes
        ...
        # bake out the locators
        cmds.bakeResults(...)
        # remove the constraints
        ...
        
    cmds.progressBar(gMainProgressBar, edit=True, endProgress=True)

The progress bar and text does shows up in the bottom left hand but the progress seemingly only starts at 1-3% (no increments thereafter) and the whole bar ends shortly after.

I was hoping something along the line such as, when it creates the locators, it will be 5%, when it went to the constraints, it will be 10% etc.


kiteh

unread,
Oct 18, 2019, 3:44:31 PM10/18/19
to Python Programming for Autodesk Maya
By the way, I always tried with "text" only where I am doing something as follows:
import maya.mel
def progress_bar_text(text):
    gMainProgressBar = maya.mel.eval('$tmp = $gMainProgressBar')
    cmds.progressBar(gMainProgressBar, edit=True, status=text)

    if gMainProgressBar:
      cmds.progressBar(gMainProgressBar, edit=True, status='')

However it does not seems to be showing any text, most likely suppress by the ` Warning: Cycle on '<name of the attribute>... may not evaluate as expected.  (Use 'cycleCheck -e off' to disable this warning.) # ` from the `bakeResults` I have used.

It does showcase my text only after the whole process has ended...

Justin Israel

unread,
Oct 18, 2019, 5:15:07 PM10/18/19
to python_in...@googlegroups.com
There needs to be a correlation between your min/max progress bar setting, and the step value. But it looks like you set up the range based on an input start/end frame and then base the progress bar step on the number of selections. That will make your progress bar hang around at a low value if you have a large frame range input and only a few selections. 
Since Maya is not doing anything magical with your method calls to know when to increment your progress, that means you need to come up with a better fitting min/max and an appropriate time to step. 

I would suggest first getting your selection. Let's say there are 10 items. Then you can take the number if steps that you have to do in each loop and multiply your selection. 

Max = len(sel) * 5

Now you can call step=1 after each of those 5 operations in your loop. The progress bar will increment based on your real work. 



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/149cbf92-a2a3-42b9-b581-055fe25bfa49%40googlegroups.com.

kiteh

unread,
Oct 18, 2019, 7:13:56 PM10/18/19
to Python Programming for Autodesk Maya
Hi Justin,

Many thanks for the input.
I have one more problem, trying to change the text in the progress bar.

And so, I did something like this:
def get_progress_bar(status_text, max_value):
    try:
        progress_bar = mel.eval("$tmp = $gMainProgressBar")
    except RuntimeError:
        progress_bar = None

    if progress_bar:
        cmds.progressBar(
            progress_bar,
            edit=True,
            beginProgress=True,
            isInterruptable=False,
            status=status_text,
            maxValue=max_value
        )
    return progress_bar


def anim_bake():
    ...
    main_progress_bar = get_progress_bar("Baking animation", len(ctrls)*5)
    ...
    ...
    for i in something:
        ...
        cmds.progressBar(main_progress_bar, edit=True, step=1)
    cmds.progressBar(main_progress_bar, edit=True, endProgress=True)
    

def set_attr():
    ...
    main_progress_bar = get_progress_bar("Setting Attrs", len(ctrls)*5)
    ...
    ...
    for i in something:
        ...
        cmds.progressBar(main_progress_bar, edit=True, step=1)
    cmds.progressBar(main_progress_bar, edit=True, endProgress=True)
    
    anim_bake()


When running my code, it seemingly, bypass one of the status text that I have made. Eg. First it displays `Setting Attrs`, but as soon as it starts to run `anim_bake`, instead of the text to showcase it as `Baking Animation`, there are times it either shows up blank, or even if I moved `anim_bake()` as a button, the text is still not shown.

At times, 'Baking animation' may be shown if I restart the tool.. Any ideas?

Justin Israel

unread,
Oct 18, 2019, 9:35:04 PM10/18/19
to python_in...@googlegroups.com
No too sure on that one. I would assume the call to edit the progress bar would refresh the draw of text. 

Hopefully my previous suggestion made sense and those are just placeholder '*5' values for how many operations and step calls you really have in your different loops. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages