Examples

Simplified submenu creation with build_submenu_dict

  • This creates a dictionary of lists from the name paths in MenuItemDescription, expanding the path and creating (multiple, if required) sub_menu lists. The last item on the path is assumed to be not a sub_menu item.

menu_dict = omni.kit.menu.utils.build_submenu_dict([ MenuItemDescription(name="File/Open"),
                                                     MenuItemDescription(name="Edit/Select/Select by kind/Group"),
                                                     MenuItemDescription(name="Window/Viewport/Viewport 1"),
                                                     MenuItemDescription(name="Help/About"),
                                                    ])

using add_menu_items

for group in menu_dict:
    omni.kit.menu.utils.add_menu_items(menu_dict[group], group)

using remove_menu_items

for group in menu_dict:
    omni.kit.menu.utils.remove_menu_items(menu_dict[group], group)

Another example: Adding a menu with submenu for your extension;

from omni.kit.menu.utils import MenuItemDescription

import carb.input

def on_startup(self, ext_id):
    self._file_menu_list = [
        MenuItemDescription(
            name="Sub Menu Example",
            glyph="file.svg",
            sub_menu=[
                MenuItemDescription(
                    name="Menu Example 1",
                    onclick_action=("omni.kit.menuext.extension", "menu_example_1"),
                ),
                MenuItemDescription(
                    name="Menu Example 2",
                    onclick_action=("omni.kit.menuext.extension", "menu_example_2"),
                )],
            )]
    omni.kit.menu.utils.add_menu_items(self._file_menu_list, "File")

def on_shutdown(self):
    omni.kit.menu.utils.remove_menu_items(self._file_menu_list, "File")

Adding to create menu

self._create_menu_list = [
    MenuItemDescription(
        name="Scope",
        glyph="menu_scope.svg",
        appear_after="Camera",
        onclick_action=("omni.kit.menu.create", "create_prim_scope"),
    )
]

omni.kit.menu.utils.add_menu_items(self._create_menu_list, "Create")