Hello!
I've been working on a tool in 3ds Max using Python, where I aim to dynamically update a Qt toolbar based on user actions. Specifically, I want to change the toolbar's content when the user adds a modifier to an object in the scene.
I'm utilizing PySide2 and QtMax
Here's the overview of what I want to achieve:
- The user adds a modifier to an object.
- A callback is triggered capturing this event.
- The callback function then updates the Qt toolbar with the latest modifier's name.
I've tried multiple approaches but the toolbar does not update dynamically. The callback is working correctly and I'm able to capture the modifier's name, but the toolbar remains unchanged.
Here's a simplified version of the code I'm using:
import re
from PySide2 import QtWidgets
from qtmax import GetQMaxMainWindow
from pymxs import runtime as rt
class RecentModifiersToolbar:
def __init__(self):
self.toolbar = self.create_toolbar()
rt.callbacks.addScript(rt.Name("postModifierAdded"), "python.execute('toolbar.modifier_changed()')", id=rt.Name("RecentModifiersCallback"))
def create_toolbar(self):
main_window = GetQMaxMainWindow()
toolbar = QtWidgets.QToolBar("Recent Modifiers", main_window)
toolbar.setObjectName("RecentModifiersTB")
test_action = QtWidgets.QAction("Test Content", toolbar)
toolbar.addAction(test_action)
main_window.addToolBar(toolbar)
toolbar.show()
return toolbar
def modifier_changed(self):
current_modifier = rt.modPanel.getCurrentObject()
if not current_modifier:
return
match = re.search(r', (.+?):', str(current_modifier))
if match:
mod_name = match.group(1).strip()
self.toolbar.actions()[0].setText(mod_name)
else:
print(f"Failed to extract modifier name from: {current_modifier}")
toolbar = RecentModifiersToolbar()
Console logs confirm that the modifier names are being captured correctly. However, the toolbar's first button (test button) doesn't change its label to the modifier's name.
If anyone has experience with this or knows why the dynamic UI update might not be taking effect, I'd be extremely grateful for guidance.
Thank you!