Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic Update of a Qt Toolbar in 3ds Max Using Python

0 REPLIES 0
Reply
Message 1 of 1
everlite1knight
269 Views, 0 Replies

Dynamic Update of a Qt Toolbar in 3ds Max Using Python

 

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:

  1. The user adds a modifier to an object.
  2. A callback is triggered capturing this event.
  3. 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!

Labels (7)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report