3
$\begingroup$

I am loosing my mind here.

Every example addon in blender uses bpy.types.INFO_MT_file_export yet not a single doc explains where the hell the name INFO_MT_file_export comes from.

The doc for bpy.types doesn’t have anything about it. Which leads me to believe we are accessing some object.

I can draw the conclusion that it’s a bl_idname for the info menu and the export submenu, but I don’t understand why we can access it using the dot operator inside of bpy.types, or why we can call the append and remove function if it’s a type of Menu.

Moreover, is there a list or something of all of these predefined possible menu ids?

$\endgroup$

1 Answer 1

7
$\begingroup$

Mousing over the base of a menu gives you the bl_idname.

enter image description here

Note that the "Open on mouse over" option in Interface > Menus must be DISABLED or else the menu will open and the tooltip won't show. Or at least increase the delay to 1 second or so

If you right click and select edit source it will open up the code for that space in the text editor enter image description here

In this file you will find

class INFO_MT_file_export(Menu):
    bl_idname = "INFO_MT_file_export"
    bl_label = "Export"

    def draw(self, context):
        if bpy.app.build_options.collada:
            self.layout.operator("wm.collada_export", text="Collada (Default) (.dae)")
        if bpy.app.build_options.alembic:
            self.layout.operator("wm.alembic_export", text="Alembic (.abc)")

which affirms that it is a Menu class. The naming convention used by blender for operators and menus is <SPACE>_<TYPE>_<name> where in this case it's the INFO space, is menu type MT and named file_export.

When a blender menu (or operator) is registered it becomes known to bpy.types. If the naming convention is followed, we can find all menus in the info space, simply by using auto-complete in the python console.

>>> bpy.types.INFO_MT_
                      add(
                      armature_add(
                      ...
                      file(
                      file_export(
                      file_external_data(
                      file_import(
                      file_previews(
                      ...
                      window(

To get a complete list of all menus, you can use python's built-in dir() function:

base_type = bpy.types.Menu
for typename in dir(bpy.types):
    bl_type = getattr(bpy.types, typename)
    if issubclass(bl_type, base_type):
        print (bl_type)
$\endgroup$
6
  • $\begingroup$ One last question, how come are we able to use append and remove? Those functions are present in the Menu class, or are they added by the subclass? $\endgroup$ Commented Jun 5, 2018 at 13:03
  • 1
    $\begingroup$ Aka, not documented at all... $\endgroup$ Commented Jun 5, 2018 at 14:20
  • 1
    $\begingroup$ Just adding for posterity: Settings->Display->Python Tooltips must be enabled to get the bl_idname to show up when mousing over menus. $\endgroup$
    – Buretto
    Commented Dec 3, 2020 at 20:02
  • 1
    $\begingroup$ Also note that the "Open on mouse over" option in Interface > Menus must be DISABLED or else the menu will open and the tooltip won't show. Or at least increase the delay to 1 second or so $\endgroup$
    – Gorgious
    Commented Oct 22, 2021 at 9:37
  • 1
    $\begingroup$ Cheers, edited. Mouse over is my preferred option these days. $\endgroup$
    – batFINGER
    Commented Oct 22, 2021 at 11:16

You must log in to answer this question.

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