How to add a Button to the Toolbar using Python?

Edit → Editor Preferences

Enable the Tools Menu Edit in the command line

Image 03

This will help you see all the various names that Unreal uses for the various Toolbars and Menus. In this case the sequencer was the target so we get the names from there

To get the icon we want, we use the Atlas found in Tools → Debug → Widget Reflector

Image 05

Run the script below, And Voila, A very big button in the Sequencer, I guess you can tone in down use a smaller icon

import unreal 

# ========== Some Class.py somewhere 
@unreal.uclass()
class PythonButtonExample(unreal.ToolMenuEntryScript):
    @unreal.ufunction(override=True)
    def execute(self, context):
        print("Wow! Print is still the king of debug! LOL")

# ========== End of Button Example

menus = unreal.ToolMenus.get()

# "Sequencer.MainToolBar" <- You can change this to be any part or
# Unreal, I just so happened to need a button for the sequencer
sequencerMenu = menus.extend_menu("Sequencer.MainToolBar")


menuScriptData = unreal.ToolMenuEntryScriptData( menu = sequencerMenu.menu_name,
                                # section = "Sequencer.MainToolBar",
                                name = "SomeName",
                                label = "Refresh Camera",
                                tool_tip = "Re Import the Camera Animation In a Jiffy",

                                # The icons you an get them from the Tools -> Debug -> Widget Reflector
                                icon = unreal.ScriptSlateIcon("EditorStyle", "ClassThumbnail.CameraAnim"),
                                insert_position = unreal.ToolMenuInsert("LevelSequenceEditor", unreal.ToolMenuInsertType.FIRST ) )

menuScript = PythonButtonExample()
menuScript.set_editor_property("data", menuScriptData)

entry = unreal.ToolMenuEntry(   name = "SomeNameEntry",
                                type = unreal.MultiBlockType.TOOL_BAR_BUTTON,
                                script_object = menuScript )

sequencerMenu.add_menu_entry("LevelSequenceEditor", entry)
menus.refresh_all_widgets()

Final Result

3 Likes