1
$\begingroup$

I try to add custom menus to the menus at the top bar in 2.80. The old INFO_HT_HEADER.append() doesn't work any more. I found TOPBAR_HT_upper_bar.append() to kind of do the trick but I get two menus, one after the workspace tabs (would preferably have it before but I guess that is a feature request separate from this) and one after the view layer menu. Am I using the wrong thing or is this a bug? Here's a super simple menu from an example which gives me the problem.

import bpy

class customMenu(bpy.types.Menu):
    bl_label = "Custom Menu"
    bl_idname = "view3D.custom_menu"

def draw(self, context):
    layout = self.layout
    layout.operator("mesh.primitive_cube_add")


def draw_item(self, context):
    layout = self.layout
    layout.menu(customMenu.bl_idname)

bpy.utils.register_class(customMenu)
bpy.types.TOPBAR_HT_upper_bar.append(draw_item)

enter image description here

$\endgroup$
2
$\begingroup$

If you want additional menus in the top bar you can add them to TOPBAR_MT_editor_menus. The following code adds a menu called Custom Menu with a sub menu that contains an operator. The draw() function of TOPBAR_MT_custom_menu is for drawing the sub menu, while menu_draw() is appended to the TOPBAR_MT_editor_menus in order to draw the menu itself.

enter image description here

import bpy


class TOPBAR_MT_custom_sub_menu(bpy.types.Menu):
    bl_label = "Sub Menu"

    def draw(self, context):
        layout = self.layout
        layout.operator("mesh.primitive_cube_add")


class TOPBAR_MT_custom_menu(bpy.types.Menu):
    bl_label = "Custom Menu"

    def draw(self, context):
        layout = self.layout
        layout.menu("TOPBAR_MT_custom_sub_menu")

    def menu_draw(self, context):
        self.layout.menu("TOPBAR_MT_custom_menu")


classes = (TOPBAR_MT_custom_sub_menu, TOPBAR_MT_custom_menu)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.TOPBAR_MT_editor_menus.append(TOPBAR_MT_custom_menu.menu_draw)


def unregister():
    bpy.types.TOPBAR_MT_editor_menus.remove(TOPBAR_MT_custom_menu.menu_draw)
    for cls in classes:
        bpy.utils.unregister_class(cls)



if __name__ == "__main__":
    register()
$\endgroup$
1
  • $\begingroup$ Switching TOPBAR_HT_upper_bar to TOPBAR_MT_editor_menus solven my problem, thanks. $\endgroup$ – Simon Rainerson Oct 30 '19 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.