Remove_menu_items leaving empty menu

I am following Isaac Sim tutorials to setup my own extension. Upon starting my extension, I setup new menu items, which I remove when the extension is shut down. For this, I use remove_menu_items. It may happen that after removing items, the menu is empty. In this case, I want to remove the whole menu.

I am missing a function to show the list of menu items so I can decide whether to delete the menu. I am also missing a function to delete the menu itself and refresh the menu.

Right now I am using private functions to achieve this:

    def on_shutdown(self):                                                               
        remove_menu_items(self._menu_items, "DSD")
        self._menu_items = None     
        instance = get_instance()
        if len(instance._menu_defs['DSD']) == 0:          
            print("Deleting DSD menu")
            del instance._menu_defs['DSD']

Hello @bruno.vetter! I’ve let the dev team know about your questions.

In the meantime, here is a link to our Extension Documentation: Kit Programming Manual

Hi @bruno.vetter! I did some searching and came across this code which may help.

What’s the correct way to remove a menu? remove_menu_items appears to remove menu items but leave the menu entry, even if it’s then empty. Here’s my hacky workaround:

    menu_utils.remove_menu_items(self._menu_items, MENU_TITLE)
    menu_defs = menu_utils.get_instance()._menu_defs
    # If menu is empty, remove it
    if MENU_TITLE in menu_defs and len(menu_defs[MENU_TITLE]) == 0:

Thanks Wendy,

this looks quite similar to my approach. It also relies on using private attributes which I also consider a hacky workaround. Although it helps, my suggestion would be to extend the api to allow for menu removal via a public method or function.