How to write a progress bar in Max using python script?

How to write a progress bar in Max using python script?

Anonymous
Not applicable
2,329 Views
6 Replies
Message 1 of 7

How to write a progress bar in Max using python script?

Anonymous
Not applicable

I have written i python script and it works.

Now i want to add a function in my python script, to show a progress bar in 3ds Max. 

Is there any inside API in 3ds Max to achieve Progress Bar like Tqdm but in Max UI instead?

Thanks 🙂

0 Likes
Accepted solutions (1)
2,330 Views
6 Replies
Replies (6)
Message 2 of 7

drew_avis
Autodesk
Autodesk

I would use the PySide2 / Qt progressbar widget.  Here's the "demoPyQWidget.py" example, I've added a progress bar and a button that randomly sets the progress value, just so you can see what it looks like.  

 

'''
	Demonstrates how to create a QWidget with PySide2 and attach it to the 3dsmax main window.
'''

from PySide2 import QtCore
from PySide2 import QtWidgets
import pymxs
import random

def make_cylinder():
	cyl = pymxs.runtime.Cylinder(radius=10, height=30)
	pymxs.runtime.redrawViews()
	return	

class PyMaxDialog(QtWidgets.QDialog):
	def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
		super(PyMaxDialog, self).__init__(parent)
		self.setWindowTitle('Pyside Qt Window')
		self.initUI()
	
	def setProgress(self):
		self.progressbar.setValue(random.randint(1,100))
		
	def initUI(self):
		main_layout = QtWidgets.QVBoxLayout()
		label = QtWidgets.QLabel("Click button to create a cylinder in the scene")
		main_layout.addWidget(label)

		cylinder_btn = QtWidgets.QPushButton("Cylinder")
		cylinder_btn.clicked.connect(make_cylinder)
		main_layout.addWidget(cylinder_btn)
		
		self.progressbar=QtWidgets.QProgressBar()
		main_layout.addWidget(self.progressbar)
		
		prog_btn = QtWidgets.QPushButton("Progress")
		prog_btn.clicked.connect(self.setProgress)
		main_layout.addWidget(prog_btn)
		
		self.setLayout(main_layout)
		self.resize(250, 100)	
		

def main():
	w = PyMaxDialog()
	w.show()	

if __name__ == '__main__':
	main()

Hope that helps,

Drew

 



Drew Avis
Content Experience Designer
0 Likes
Message 3 of 7

Anonymous
Not applicable

Thx, it really works :)Smiley Embarassed

But the whole widget hangs and i can't see the moving until 100%, while the python script is running.

${WELQIX~RW~X{IT{2YT`15.png

Can i get access to the Max original progress bar(in my py script) on the bottom of the UI like this. Maybe this will not be hang and i can see the bar moving ?

]3MY8GLS3KCHGZLRIGG~IXQ.png

0 Likes
Message 4 of 7

drew_avis
Autodesk
Autodesk
Accepted solution

Hi, yes you can access that progress bar using pymxs.  Have a look at this MAXScript topic:

 

http://help.autodesk.com/view/3DSMAX/2020/ENU/?guid=GUID-5C069EAA-E2EB-4F7B-B6AC-DECD51121348

 

Simple example:

rt = pymxs.runtime
rt.progressStart('Doing something')
for i in range (1,1000):
	rt.progressUpdate(i/10)
rt.progressEnd()

Hope that helps,

Drew



Drew Avis
Content Experience Designer
0 Likes
Message 5 of 7

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

Thx, it really works :)Smiley Embarassed

But the whole widget hangs and i can't see the moving until 100%, while the python script is running.

 


because you do something wrong. show your code and we will be able to say what you do wrong specifically.

 

0 Likes
Message 6 of 7

Anonymous
Not applicable

Thank you very muchSmiley Happy, now i can get access the Status Bar of 3ds Max. Thanks again for your answer 🙂 

0 Likes
Message 7 of 7

Anonymous
Not applicable

This is how i use the progress bar:

 

	def initUI(self):
		main_layout = QtWidgets.QVBoxLayout()
                ...
		self.progressbar=QtWidgets.QProgressBar()
		main_layout.addWidget(self.progressbar)
...

# to simplify my code structure, i name the function as doSomething()
def my-for-loop:
for i in range(1000):
doSomething(i)
# i set value by index
self.progressbar.setValue(100.0 * (1 + i) / 1000)

I want to show how the for-loop advancing, so i put a progress bar. But whenever the for-loop starts, 3ds Max hangs itself, and i can't see the bar moving until loop finish 😞

 

0 Likes