0
$\begingroup$

I want to make it so I (and my students) can access the Graph Editor's "Key" menu from the Timeline. This is very easy to do by changing the source code: in space_time.py I just need to add sub.menu("GRAPH_MT_key") under the class TIME_MT_editor_menus(Menu): as shown in this screenshot:

enter image description here

However, I would really like to do this via an addon so that it is easier to distribute to my students. I am relatively new to addon coding, so I am probably missing something huge, but it seems like all we should need to do is append the Key menu to the Timeline editor menus. I tried the following, but it didn't work:

bl_info = {
    "name": "Timeline Key Menu",
    "blender": (3, 6, 0),
    "location": "Timeline > Key",
    "description": ("Adds the graph editor's Key menu to the Timeline window"),
    "category": "Animation",
}

import bpy


def register():
    bpy.types.TIME_MT_editor_menus.append(bpy.types.GRAPH_MT_key)  

def unregister():
    bpy.types.TIME_MT_editor_menus.append(bpy.types.GRAPH_MT_key)


if __name__ == "__main__":
    register()

Any thoughts on what I'm missing?

$\endgroup$
2
  • $\begingroup$ Hi. Please use a title that matches the content of the question. It should be descriptive but succinct, unique and identifying, summarizing the issue in such way that anyone searching for a similar problem is likely to find it. Use the edit link above, remove anything superfluous, avoid words like "this", "help", "issue with" or "question about". Remember, your title is the first thing potential visitors see, answers you get depend heavily on how insightful it is. See What is the problem of asking “How do I do this?" $\endgroup$ Commented Sep 23, 2023 at 23:06
  • $\begingroup$ Out of curiosity, which menu items do you want to reach, not available from a right-click? $\endgroup$
    – Robin Betts
    Commented Sep 30, 2023 at 7:53

1 Answer 1

1
$\begingroup$

bpy.types.TIME_MT_editor_menus.append() takes a draw function as parameter.

Below is a sample code also available in Templates > Python > Ui Menu in the Blender Text Editor.

import bpy


class CustomMenu(bpy.types.Menu):
    bl_label = "Custom Menu"
    bl_idname = "OBJECT_MT_custom_menu"

    def draw(self, context):
        layout = self.layout

        layout.operator("wm.open_mainfile")
        layout.operator("wm.save_as_mainfile").copy = True

        layout.operator("object.shade_smooth")

        layout.label(text="Hello world!", icon='WORLD_DATA')

        # use an operator enum property to populate a sub-menu
        layout.operator_menu_enum("object.select_by_type",
                                  property="type",
                                  text="Select All by Type",
                                  )

        # call another menu
        layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"


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


def register():
    bpy.utils.register_class(CustomMenu)

    # lets add ourselves to the main header
    bpy.types.INFO_HT_header.append(draw_item)


def unregister():
    bpy.utils.unregister_class(CustomMenu)

    bpy.types.INFO_HT_header.remove(draw_item)


if __name__ == "__main__":
    register()

    # The menu can also be called from scripts
    bpy.ops.wm.call_menu(name=CustomMenu.bl_idname)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .