2
$\begingroup$

I can add an item My Item using the script at the bottom.

enter image description here

Currently I only know how to add the item to the same flat list in the Export category like in the script at the bottom, but I would like to know how to group them into another sub category Group of Items. Is this even possible? The list is very long and I don't want it to be part of the flat list with the default types. I would like this:

enter image description here

Or maybe I can add it alongside File > Import and File > Export as type File > Export Group 2 group, but how to do that?

enter image description here

Here's the script:

import bpy

class SimpleExportOperator(bpy.types.Operator):
    bl_idname = "export.simple_operator"
    bl_label = "Simple Export Operator"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        self.report({'INFO'}, "Executing Simple Export Operator")
        return {'FINISHED'}

def menu_func_export_my_item(self, context):
    self.layout.operator(SimpleExportOperator.bl_idname, text="My Item")

def register():
    bpy.utils.register_class(SimpleExportOperator)
    bpy.types.TOPBAR_MT_file_export.append(menu_func_export_my_item)

def unregister():
    bpy.utils.unregister_class(SimpleExportOperator)
    bpy.types.TOPBAR_MT_file_export.remove(menu_func_export_my_item)

if __name__ == "__main__":
    register()
$\endgroup$

1 Answer 1

2
$\begingroup$

here is an example (it is too much so, but i think you can figure it out) - i was too lazy to delete the superfluous stuff

import bpy

class SimpleExportOperator(bpy.types.Operator):
    bl_idname = "export.simple_operator"
    bl_label = "Simple Export Operator"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        self.report({'INFO'}, "Executing Simple Export Operator")
        return {'FINISHED'}

def menu_func_export_my_item(self, context):
    
    self.layout.operator(SimpleExportOperator.bl_idname, text="My Item2")
    
    self.layout.menu(SubMenu2.bl_idname, text="submenu")

def register():
    bpy.utils.register_class(SubMenu2)
    bpy.utils.register_class(SimpleExportOperator)
    bpy.types.TOPBAR_MT_file_export.append(menu_func_export_my_item)

def unregister():
    bpy.utils.unregister_class(SimpleExportOperator)
    bpy.types.TOPBAR_MT_file_export.remove(menu_func_export_my_item)



class SubMenu2(bpy.types.Menu):
    bl_idname = "TOPBAR_MT_select_submenu"
    bl_label = "Select"

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

        layout.operator("object.select_all", text="Select/Deselect All").action = 'TOGGLE'
        layout.operator("object.select_all", text="Inverse").action = 'INVERT'
        layout.operator("object.select_random", text="Random")

        # access this operator as a submenu
        layout.operator_menu_enum("object.select_by_type", "type", text="Select All by Type...")

        layout.separator()

        # expand each operator option into this menu
        layout.operator_enum("object.lamp_add", "type")

        layout.separator()

        # use existing memu
        layout.menu("VIEW3D_MT_transform")




if __name__ == "__main__":
    register()

result:

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ perfect just what i needed thanks alot chris! $\endgroup$
    – Harry McKenzie
    Commented Jan 22 at 16:33
  • 1
    $\begingroup$ you are welcome! $\endgroup$
    – Chris
    Commented Jan 23 at 6:04

You must log in to answer this question.

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