[Maya-Python] Get progress from file import

81 views
Skip to first unread message

Marcus Ottosson

unread,
May 22, 2014, 10:13:05 AM5/22/14
to python_in...@googlegroups.com

Hey guys,

When running an import, say of a 2 gb file, there is a progress bar lurking in the Help panel. Does anyone know how to tap into that one?

E.g.

import time
import threading
import maya.cmds
import maya.utils

path = r'/home/big_file.ma'

def thread():    
    maya.utils.executeInMainThreadWithResult(maya.cmds.file, path, i=True)

thread = threading.Thread(target=thread)
thread.daemon = True
thread.start()

# I'm looking for this one, to give me
# updates on progress, so that I can use it
# in a GUI.
progress = None

# Example use
while progress:
    print progress.value
    time.sleep(0.1)

print "Done"

Best,
Marcus

--
Marcus Ottosson
konstr...@gmail.com

Justin Israel

unread,
May 22, 2014, 5:19:57 PM5/22/14
to python_in...@googlegroups.com
You could grab the reference to the main progress bar and connect to its signal:

import maya.OpenMayaUI as mui

from PySide import QtGui
import shiboken

ptr = mui.MQtUtil.mainWindow()
win = shiboken.wrapInstance(long(ptr), QtGui.QWidget)

prog = win.findChild(QtGui.QProgressBar)
print prog.objectName()

def print_progress(val):
    print "Progress!", val

prog.valueChanged.connect(print_progress)

But be careful not to do anything big in your slot since it will hold up the app :-)

Using the thread doesn't really help here since it will still place the call into the main event loop and as soon as your file process starts, none of your other code will get called. So you kind of need the slot connection to the progress bar since it is being used as part of that call. However, you could feed the progress to something else running in a thread to handle stuff that needs to do more work. 
Reply all
Reply to author
Forward
0 new messages