<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Dynamic Update of a Qt Toolbar in 3ds Max Using Python in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/dynamic-update-of-a-qt-toolbar-in-3ds-max-using-python/m-p/12189849#M2056</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm utilizing PySide2 and QtMax&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the overview of what I want to achieve:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The user adds a modifier to an object.&lt;/LI&gt;&lt;LI&gt;A callback is triggered capturing this event.&lt;/LI&gt;&lt;LI&gt;The callback function then updates the Qt toolbar with the latest modifier's name.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here's a simplified version of the code I'm using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2023 03:34:40 GMT</pubDate>
    <dc:creator>everlite1knight</dc:creator>
    <dc:date>2023-08-23T03:34:40Z</dc:date>
    <item>
      <title>Dynamic Update of a Qt Toolbar in 3ds Max Using Python</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/dynamic-update-of-a-qt-toolbar-in-3ds-max-using-python/m-p/12189849#M2056</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm utilizing PySide2 and QtMax&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the overview of what I want to achieve:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The user adds a modifier to an object.&lt;/LI&gt;&lt;LI&gt;A callback is triggered capturing this event.&lt;/LI&gt;&lt;LI&gt;The callback function then updates the Qt toolbar with the latest modifier's name.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Here's a simplified version of the code I'm using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 03:34:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/dynamic-update-of-a-qt-toolbar-in-3ds-max-using-python/m-p/12189849#M2056</guid>
      <dc:creator>everlite1knight</dc:creator>
      <dc:date>2023-08-23T03:34:40Z</dc:date>
    </item>
  </channel>
</rss>

