How to handle Cancel during BakeToTexture from script?

How to handle Cancel during BakeToTexture from script?

elpie89
Advocate Advocate
170 Views
10 Replies
Message 1 of 11

How to handle Cancel during BakeToTexture from script?

elpie89
Advocate
Advocate

 

Hi all,

I’m automating Bake to Texture in 3ds Max 2026 (with Arnold).
When I launch baking from the UI, the “Baking Progress (Arnold)” dialog appears and remains responsive: the Cancel button and ESC key work as expected.

When I call baking from script, however, the situation is different:

 

BakeToTexture.autoCloseProgressDialog = false
BakeToTexture.showFrameBuffer = true
BakeToTexture.bake()
 
 
  • The “Baking Progress (Arnold)” dialog does not show.

  • My own PySide2 QDialog shows before the bake, but once the bake starts it becomes frozen (no button clicks or keypresses are processed).

  • I understand this is because the render loop blocks the main UI thread, but the native progress window somehow still accepts Cancel.

Questions:

  1. Is there a way to force the native “Baking Progress (Arnold)” dialog to appear when calling 

BakeToTexture.bake()

from script?

  • If not, is there any supported way to create a custom cancel mechanism (via a Qt dialog, keyboard shortcut, etc.) that remains functional while baking?

  • More generally, how does the native BakeToTexture progress dialog remain responsive to Cancel when the render blocks the main thread?

Any guidance or code snippets would be appreciated — I’d like to give users a reliable Cancel button when baking via script.

Thanks!

 
 

 

 

0 Likes
Accepted solutions (1)
171 Views
10 Replies
Replies (10)
Message 2 of 11

miauuuu
Collaborator
Collaborator

I don't have 3ds max 2026 but what happen when you first use this:

BakeToTexture.showDialog()

 

and then

 

BakeToTexture.bake()

 

or programmatically press the button in BakeToTexture dialog which will start backing.

https://miauu-maxscript.com/
0 Likes
Message 3 of 11

elpie89
Advocate
Advocate

BakeToTexture.showDialog()

BakeToTexture.bake()  does not open the “Baking Progress (Arnold)” window

 

 

how do you do that ? -> programmatically press the button in BakeToTexture dialog which will start backing.

0 Likes
Message 4 of 11

miauuuu
Collaborator
Collaborator

Usually, to press a button programmatically the UIAccessors methods have to be used. If the “Baking Progress (Arnold)” window is a QT window then you can try with python methods.

https://miauu-maxscript.com/
0 Likes
Message 5 of 11

elpie89
Advocate
Advocate

i tried to run the bake with ui accessor

UIAccessor.PressButtonByName 4067032P "Bake"
UIAccessor.SendMessageID 4067032P #IDOK

none of this work 

0 Likes
Message 6 of 11

miauuuu
Collaborator
Collaborator

Quick snippet:

(
	builtin = python.import "builtins"	
	QtWidgets = python.import "PySide6.QtWidgets"
	
	BakeToTexture.showDialog()
		
	GetQMaxMainWindow = (python.import "qtmax").GetQMaxMainWindow
	cArr = ((GetQMaxMainWindow()).children()) as array
	
	for child in cArr where matchPattern child pattern:"*BTTMainDialog*" do
	(		
		w0 = QtWidgets.QWidget.find (child.winId())		
		w0Arr = w0.children() as array
		
		for w0 in w0Arr do
		(	
			try
			(
				w1 = QtWidgets.QWidget.find (w0.winId())
				w1Arr = w1.children() as array
				
				for w1 in w1Arr do
				(
					try
					(
						w2 = QtWidgets.QWidget.find (w1.winId())
						w2Arr = w2.children() as array
						
						for n in w2Arr where matchPattern n pattern:"*bakeOptionsGroup*" do
						(
							w3 = QtWidgets.QWidget.find (n.winId())
							w3Arr = w3.children() as array
							for b in w3Arr where matchPattern b pattern:"*bakeMapButton*" do
							(
								b.click()
							)
						)
						
					)
					catch()
				)	
			)
			catch()
		)
	)
)
https://miauu-maxscript.com/
0 Likes
Message 7 of 11

denisT.MaxDoctor
Advisor
Advisor
Accepted solution
qtwidgets = python.import "PySide2.QtWidgets" ----- or PySide6
shiboken = python.import "shiboken2" ----- or shiboken6

(
	BakeToTexture.alwaysOverwriteExistingFiles = true -- or do what you need
	BakeToTexture.showDialog()

	all_top_widgets = qtwidgets.QApplication.topLevelWidgets()
	bake_dialog = for x in all_top_widgets as array where shiboken.isValid x and (x.objectName() == "BTTMainDialog") do exit with x
	bts = bake_dialog.findChildren qtwidgets.QToolButton
	bake_button = for b in bts as array where b.objectName() == "bakeMapButton" do exit with b
	bake_button.animateClick()
)

 

Do everything else yourself to ensure “ foolproofness.”

Message 8 of 11

elpie89
Advocate
Advocate
bake_dialog = for x in all_top_widgets as array where shiboken.isValid x and (x.objectName() == "BTTMainDialog") do exit with x
bake_dialog = x.findChildren qtwidgets.QToolButton

 A side from this  micro modification works like a charm. 

Thanks

0 Likes
Message 9 of 11

denisT.MaxDoctor
Advisor
Advisor

why?

bake_dialog = x.findChildren qtwidgets.QToolButton

-- OH!

bts = bake_dialog.findChildren qtwidgets.QToolButton
 
0 Likes
Message 10 of 11

denisT.MaxDoctor
Advisor
Advisor

BTW...  there is a shortcut:

	bake_button = (bake_dialog.findChildren qtwidgets.QToolButton "bakeMapButton")[0]
	if shiboken.isValid bake_button do bake_button.animateClick()
Message 11 of 11

elpie89
Advocate
Advocate

yeah sorry , i fixed it properly on max then modified wrongly on the forum . 

 

0 Likes