Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to rename buttons in the UI using Add-inn's

gerrieYAQRA
Explorer

How to rename buttons in the UI using Add-inn's

gerrieYAQRA
Explorer
Explorer

I am trying to rename the existing buttons to something else. Lets say - rename the sketch button to "Begin Teken" which means "start drawing" in another language. I have been going through User-Interface Customization articles and command articles to find the command/code to do the changes but nothing has exactly what I am looking for. Am I missing something? 

Here is what I have gone through already:
UI Customization 

Commands

And even Python Templates

These are quite lengthy and take a lot of time to understand/execute. This doesn't mention how to change existing code to display what I would like it to.. in the end.

 

0 Likes
Reply
Accepted solutions (4)
613 Views
7 Replies
Replies (7)

kandennti
Mentor
Mentor
Accepted solution

Hi @gerrieYAQRA -San.

 

It is probably not possible to rename the native command button (ToolbarControl).

 

Instead, we have created a sample add-in that hides the native sketch command and adds a new "Begin Teken" command.
When the "Begin Teken" command is executed, the native sketch command is executed.

#FusionAPI_python addin

import traceback
import adsk.core
import adsk.fusion

_app = adsk.core.Application.cast(None)
_ui  = adsk.core.UserInterface.cast(None)
_handlers = []

_cmdInfo = {
    "id": "Begin Teken",
    "name": "Begin Teken",
    "tooltip": "Begin Teken",
    }

_toolBarInfo = {
    "workspace": "FusionSolidEnvironment",
    "tab": "SolidTab",
    "panel": "SolidCreatePanel"
}


def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs: adsk.core.CommandDefinitions = _ui.commandDefinitions

        global _cmdInfo
        cmdDef: adsk.core.CommandDefinition = cmdDefs.itemById(
            _cmdInfo["id"]
        )

        if cmdDef:
            cmdDef.deleteMe()

        sktCmdDef: adsk.core.CommandDefinition = get_create_sketch_command_definition()

        cmdDef = cmdDefs.addButtonDefinition(
            _cmdInfo["id"],
            _cmdInfo["name"],
            _cmdInfo["tooltip"],
            sktCmdDef.resourceFolder,
        )

        onCommandCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        _handlers.append(onCommandCreated)

        global _toolBarInfo
        ws: adsk.core.Workspace = _ui.workspaces.itemById(
            _toolBarInfo["workspace"]
        )

        tab: adsk.core.ToolbarTab = ws.toolbarTabs.itemById(
            _toolBarInfo["tab"]
        )

        panel: adsk.core.ToolbarPanel = tab.toolbarPanels.itemById(
            _toolBarInfo["panel"]
        )

        cmdControl: adsk.core.ToolbarControl= panel.controls.addCommand(
            cmdDef,
            sktCmdDef.id,
            False
        )
        cmdControl.isVisible = True
        cmdControl.isPromoted = True

        sktCmdControl: adsk.core.ToolbarControl = panel.controls.itemById(
            sktCmdDef.id
        )
        sktCmdControl.isVisible = False
        sktCmdControl.isPromoted = False

    except:
        if _ui:
            _ui.messageBox("Failed:\n{}".format(traceback.format_exc()))


def stop(context):
    try:
        global _toolBarInfo
        ws: adsk.core.Workspace = _ui.workspaces.itemById(
            _toolBarInfo["workspace"]
        )

        tab: adsk.core.ToolbarTab = ws.toolbarTabs.itemById(
            _toolBarInfo["tab"]
        )

        panel: adsk.core.ToolbarPanel = tab.toolbarPanels.itemById(
            _toolBarInfo["panel"]
        )

        global _cmdInfo
        if panel:
            panel.controls.itemById(_cmdInfo["id"]).deleteMe()

        cmdDefs: adsk.core.CommandDefinitions = _ui.commandDefinitions
        cmdDef: adsk.core.CommandDefinition = cmdDefs.itemById(_cmdInfo["id"])
        if cmdDef:
            cmdDef.deleteMe()

        sktCmdDef: adsk.core.CommandDefinition = get_create_sketch_command_definition()
        sktCmdControl: adsk.core.ToolbarControl = panel.controls.itemById(
            sktCmdDef.id
        )
        sktCmdControl.isVisible = True
        sktCmdControl.isPromoted = True

    except:
        print("Failed:\n{}".format(traceback.format_exc()))


def get_create_sketch_command_definition() -> adsk.core.CommandDefinition:

    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface

    cmdDefs: adsk.core.CommandDefinitions = ui.commandDefinitions
    return cmdDefs.itemById(
        "SketchCreate"
    )


class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            sktCmdDef: adsk.core.CommandDefinition = get_create_sketch_command_definition()
            sktCmdDef.execute()
        except:
            if _ui:
                _ui.messageBox("Failed:\n{}".format(traceback.format_exc()))

1.png

 

However, this can be confusing for users.
It would be more user-friendly to create a tab for your add-in and place the necessary commands as shown in this add-in.

https://github.com/AutodeskFusion360/Fusion360DevTools 

2 Likes

gerrieYAQRA
Explorer
Explorer

Hi Kandennti-san,

 

Thank you for the assist and interest.

I think this is great, thanks for the info. Before I mark this as the solution, would you kindly let me know how you know this would be (ToolbarControl) we needed to address?

If I can have a list of what each section is called, it would help a lot. If I have touched base on this on the previous articles, please let me know as this is all still new and needs to sink in.

 

Much appreciated!!

0 Likes

kandennti
Mentor
Mentor
Accepted solution
1 Like

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

@Jorge_Jaramillo - this post is being edited to remove PII.

 

hi @kandennti ,

 

You can also set the name of the command definition with the following sentence:

 

adsk.core.Application.get().userInterface.commandDefinitions.itemById("SketchCreate").name = "Begin Teken"

 

 

Look at the following image when I did it from the Text Commands panel without the need of a add-in:

wtallerdemadera_0-1690922904590.png

 

Could it be a solution?

 

Regards,

Jorge Jaramillo

 

2 Likes

kandennti
Mentor
Mentor

@Jorge_Jaramillo -San.

 

Thank you very much. I had not noticed that.
This method is much easier.

2 Likes

gerrieYAQRA
Explorer
Explorer

Hi @Jorge_Jaramillo,

 

Thanks you for your input. That would be a nice quick fix, but it would probably need to be done every time via the "text commands" whereas if we did it through an add-in, it should be one click to rename all. And also, you can have the add-in run on startup or disable it if you would like to turn it off and revert to the original state.

0 Likes

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

@Jorge_Jaramillo - this post is being edited to remove PII.

 

Hi,

The line of code I post is not a text command. It is python code, which you can include in any script/add-id. I did it that way just to show how easy it is to execute single instructions from there without the need of a script.

You can create an add-in which run on start-up to rename the buttons names you want every time Fusion 360 starts.
To revert to the original state you have to add the code to rename them back in the stop method, or to disable the add-in and restart Fusion 360; either way will work.

Regards,
Jorge Jaramillo

2 Likes