One minute
pm.progressWindow decorator
I came across this really handy script written by Jos Balcaen: http://josbalcaen.com/maya-python-progress-decorator/. I hardly ever have my Help Line open in Maya and even when I have, the progress bar down there is so small that most people miss it. So I did some modifications to his code to have a progressWindow pop up instead of updating the main progress bar.
Code:
import pymel.core as pm
# reworked from:
# http://josbalcaen.com/maya-python-progress-decorator/
class progress_window(object):
def __init__(self, status="Working...", start=0):
self.start_value = start
self.end_value = 100
self.status = status
self.step_value = 0
# kill any existing progress windows
pm.progressWindow(endProgress=True)
def update_progress(self, step_update=1, status=""):
if status == "":
status = self.status
self.step_value += step_update
pm.progressWindow(edit=True, progress=self.step_value, status=status)
def start(self):
pm.progressWindow(title=self.status, progress=1,
status=self.status,
maxValue=self.end_value,
isInterruptable=False)
def end(self):
pm.progressWindow(endProgress=True)
self.step_value = 0
def __call__(self, in_function):
def wrapped_f(*args, **kwargs):
# Start progress
self.start()
# Call original function
in_function(*args, **kwargs)
# End progress
self.end()
# Add special methods to the wrapped function
wrapped_f.update_progress = self.update_progress
# Copy over attributes
wrapped_f.__doc__ = in_function.__doc__
wrapped_f.__name__ = in_function.__name__
wrapped_f.__module__ = in_function.__module__
# Return wrapped function
return wrapped_f
Example use:
import pymel.core as pm
import nv_maya_utils.decorators as maya_decorators
import time
@maya_decorators.progress_window()
def make_spheres(amount=25):
for i in range(amount):
pm.polySphere()
time.sleep(0.1)
make_spheres.update_progress(100/amount, "Making #%s" % i)
make_spheres()
Read other posts