<?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 Re: Command button won't rename in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396044#M8674</link>
    <description>&lt;P&gt;I don't appear to be able to access your add-in, could you attach it to this forum? I am eager to see if I can find out why your add-in will rename the command button and mine won't.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jun 2021 20:18:58 GMT</pubDate>
    <dc:creator>bevis.hobbs21</dc:creator>
    <dc:date>2021-06-16T20:18:58Z</dc:date>
    <item>
      <title>Command button won't rename</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10375513#M8671</link>
      <description>&lt;P&gt;The property to rename a command button in the UI:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;CommandDefinition.name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;It is documented here:&amp;nbsp;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-cdf53108-bcaf-418e-b678-f041f2e207c4" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-cdf53108-bcaf-418e-b678-f041f2e207c4&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;And it won't work, when I set it, it doesn't change the name in the UI. The tooltip property changes the name of the tooltip fine, but the name property doesn't change the name of the&amp;nbsp;command button in the UI.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="4"&gt;Here's my code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core, adsk.fusion, traceback

button_names = [("Start calc Add-In", "Starts the calculation Add-In."),
                ("Stop calc Add-In", "Stops the calculation Add-In.")]
panel_id = "SolidScriptsAddinsPanel"
command_id = "calc_add_in"

handlers = []; running = False

app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent

def msg(message): ui.messageBox(str(message))

class CommandCreatedEventHandlerPanel(adsk.core.CommandCreatedEventHandler):

    def __init__(self):
        super().__init__()

    def notify(self, args):
        global running
        try:
            running = not running
            commandDefinitionPanel_.name = button_names[int(running)][0]
            commandDefinitionPanel_.tooltip = button_names[int(running)][1]
            msg("Calculation "+("started" if running else "stopped"))
        except:
            if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))

def run(context):
    global commandDefinitionPanel_
    try:
        workspaces_ = ui.workspaces
        modelingWorkspace_ = workspaces_.itemById("FusionSolidEnvironment")
        toolbarPanels_ = modelingWorkspace_.toolbarPanels
        toolbarPanel_ = toolbarPanels_.itemById(panel_id)
        toolbarControlsPanel_ = toolbarPanel_.controls
        toolbarControlPanel_ = toolbarControlsPanel_.itemById(command_id)

        if not toolbarControlPanel_:
            commandDefinitionPanel_ = ui.commandDefinitions.itemById(command_id)
            if not commandDefinitionPanel_:
                commandDefinitionPanel_ = ui.commandDefinitions.addButtonDefinition(
                    command_id, *button_names[0])

            toolbarControlPanel_ = toolbarControlsPanel_.addCommand(commandDefinitionPanel_)
            toolbarControlPanel_.isVisible = True

            onCommandCreated = CommandCreatedEventHandlerPanel()
            commandDefinitionPanel_.commandCreated.add(onCommandCreated)
            handlers.append(onCommandCreated)
    except:
        if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))

def commandControlByIdForPanel(id):
    if not id:
        ui.messageBox("commandControl id is not specified")
        return None
    workspaces_ = ui.workspaces
    modelingWorkspace_ = workspaces_.itemById("FusionSolidEnvironment")
    toolbarPanels_ = modelingWorkspace_.toolbarPanels
    toolbarPanel_ = toolbarPanels_.itemById(panel_id)
    toolbarControls_ = toolbarPanel_.controls
    toolbarControl_ = toolbarControls_.itemById(id)
    return toolbarControl_

def destroy_object(item):
    if item and item.isValid: item.deleteMe()

def stop(context):
    global running
    try:
        running = False

        commandDefinitions_ = ui.commandDefinitions
        commandDefinition_ = commandDefinitions_.itemById(command_id)
        destroy_object(commandDefinition_)
        commandControlPanel_ = commandControlByIdForPanel(command_id)
        destroy_object(commandControlPanel_)
    except:
        if ui: ui.messageBox("Failed:\n{}".format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 08:02:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10375513#M8671</guid>
      <dc:creator>bevis.hobbs21</dc:creator>
      <dc:date>2021-06-09T08:02:08Z</dc:date>
    </item>
    <item>
      <title>Command button won't rename</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10381369#M8672</link>
      <description>&lt;P&gt;This looks like a bug to me.&amp;nbsp; It appears that setting the name property is working but the displayed name in the panel is not updating.&amp;nbsp; I could see this because after setting the name and getting the value of the name property after, it is returning the name I set it to.&amp;nbsp; Also, after setting the name and if I choose the "Pin to Toolbar" option for the command to show the command in the toolbar, I see the new name in the tooltip.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 03:20:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10381369#M8672</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2021-06-11T03:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Command button won't rename</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396014#M8673</link>
      <description>&lt;P&gt;"Wait, I already do that in an add-in.."&lt;/P&gt;&lt;P&gt;I loaded your code and I can not for the life of me figure out why it works for my add-in but not yours:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Tried moving the update code to the Execute handler (created by the Created handler)&lt;/LI&gt;&lt;LI&gt;Tried setting resourceFolder - but on commandDefinition creation and on update&lt;/LI&gt;&lt;LI&gt;Tried putting the command def under the Utility menu&lt;/LI&gt;&lt;LI&gt;Tried putting the command def under my add-in's menu, and under a sub-menu (Dropdown). The last place is where my add-ins Record button successfully updates! :S&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have not tried:&lt;/P&gt;&lt;P&gt;Making sure the command completes successfully&lt;/P&gt;&lt;P&gt;Letting the event loop run (adsk.doEvents() or a zero delay CustomEvent) - but I can't see my add-in doing that either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My add-in, for reference: &lt;A href="https://github.com/thomasa88/AnyShortcut" target="_blank"&gt;https://github.com/thomasa88/AnyShortcut&lt;/A&gt;&amp;nbsp; AnyShortcut.py is the main file.&lt;/P&gt;&lt;P&gt;I have wrapped the Event handlers quite dramatically, so it's a bit hard to compare.., but they are the add_handler() calls.&lt;/P&gt;&lt;P&gt;You can run the add-in and see that the Record menu item updates when clicked..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fusion 360 v. 2.0.10253&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 20:00:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396014#M8673</guid>
      <dc:creator>thomasa88</dc:creator>
      <dc:date>2021-06-16T20:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Command button won't rename</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396044#M8674</link>
      <description>&lt;P&gt;I don't appear to be able to access your add-in, could you attach it to this forum? I am eager to see if I can find out why your add-in will rename the command button and mine won't.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 20:18:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396044#M8674</guid>
      <dc:creator>bevis.hobbs21</dc:creator>
      <dc:date>2021-06-16T20:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Command button won't rename</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396901#M8675</link>
      <description>&lt;P&gt;That's strange. So you can't access github at all?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realized that my DirectName add-in behaves more similar to your code and is a bit smaller. It only changes its icon by default, but I patched it to change the name, which worked fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the patched version as a zip.&lt;/P&gt;&lt;P&gt;Patch: &lt;A href="https://github.com/thomasa88/DirectName/commit/88c043fdef78a4b5c4dd791df0252fcf44e3ae9b" target="_blank" rel="noopener"&gt;https://github.com/thomasa88/DirectName/commit/88c043fdef78a4b5c4dd791df0252fcf44e3ae9b&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried disabling .isPromoted(ByDefault) in AnyShortcut without any problems. So the promotion does not seem to be part of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit.&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10832289"&gt;@bevis.hobbs21&lt;/a&gt;&amp;nbsp; Are you running Windows or Mac btw? I'm using Windows 10.&lt;/P&gt;&lt;P&gt;Edit. &lt;SPAN style="color: #795e26;"&gt;update_enable_button&lt;/SPAN&gt;() is the function that changes the text.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 04:22:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/command-button-won-t-rename/m-p/10396901#M8675</guid>
      <dc:creator>thomasa88</dc:creator>
      <dc:date>2021-06-17T04:22:04Z</dc:date>
    </item>
  </channel>
</rss>

