Progress Bar

Progress Bar

Hans_Redman
Advocate Advocate
687 Views
3 Replies
Message 1 of 4

Progress Bar

Hans_Redman
Advocate
Advocate

Does anyone know how to fix this problem? I want some like Image one, which is like has a progress bar at the top of the two buttons, but when I run the code it will look like Image two.
Here is the code:

import maya.cmds as cmds
import math
def windowUI(*args):
if cmds.window("progress_bar", exists=True):
cmds.deleteUI("progress_bar")
bar_window = cmds.window("progress_bar", title="Progress Bar", sizeable=False)
cmds.columnLayout()
cmds.separator(h=10, st='in')
#progressControl = cmds.progressBar(maxValue=100, width=300)
#cmds.separator(h=5, st='in')
cmds.rowColumnLayout(nc=2, cw=[4,2])
#Buttons
cmds.button("start_button", label="Start", w=149, command=start_part)
cmds.button("close_button", label="Close", w=149, command=close_part)

cmds.showWindow(bar_window)

def start_part(*args):

progressControl = cmds.progressBar(maxValue=100, width=300)
for i in range(10000):
for k in range(1000):
x = math.sin(math.sin(math.cos(i)))
if i%100 == 0:
cmds.progressBar(progressControl, edit=True, step=1)
def close_part(*args):
cmds.deleteUI("progress_bar")

windowUI()

 

m981780836_0-1637632007507.png

m981780836_1-1637632037951.png

 

0 Likes
Accepted solutions (1)
688 Views
3 Replies
Replies (3)
Message 2 of 4

Hans_Redman
Advocate
Advocate

Another question is how do you make the progress bar actually works? Not just go from 0% to 100%. Make it actually works.
Cheers

0 Likes
Message 3 of 4

Hans_Redman
Advocate
Advocate
Accepted solution

Fixed the first problem by use 'lambda x:' :

 

 

cmds.button("start_button", label="Start", w=149, command=lambda x: start_part(progressControl))

 

import maya.cmds as cmds
import math

def windowUI(*args):
    
    if cmds.window("progress_bar", exists=True):
        cmds.deleteUI("progress_bar")
        
    bar_window = cmds.window("progress_bar", title="Progress Bar", sizeable=False)
    
    cmds.columnLayout()
    cmds.separator(h=10, st='in')
    progressControl = cmds.progressBar(maxValue=100, width=300)
    cmds.rowColumnLayout(nc=2, cw=[4,2])
    
    #Buttons
    cmds.button("start_button", label="Start", w=149, command=lambda x: start_part(progressControl))
    cmds.button("close_button", label="Close", w=149, command=close_part)

    cmds.showWindow(bar_window)
    		
def start_part(progress_bar):
    for i in range(10000):
        for k in range(1000):
            x = math.sin(math.sin(math.cos(i)))
        if i%100 == 0:
            cmds.progressBar(progress_bar, edit=True, step=1)
            
def close_part(*args):
    cmds.deleteUI("progress_bar")

windowUI()

More information:
https://forums.cgsociety.org/t/python-passing-arguments-from-a-button-to-a-function/1573367/3
Hope this helps

0 Likes
Message 4 of 4

Hans_Redman
Advocate
Advocate

How to add a gap between buttons?? Something like the 3 buttons at the top.

m981780836_0-1637715017359.png

 

0 Likes