eduardo simioni

FBMenuManager, FBGenericMenu and FBGenericMenuItem

by on Aug.21, 2013, under GUI, interface, MotionBuilder, python

If this was explained somewhere in Motionbuilder’s help it would have made my day yesterday so much easier. Anyway:

FBMenuManager(): the manager
FBGenericMenu(): a menu with FBGenericMenuItem()s inside
FBGenericMenuItem(): an item inside a menu, where something happens when you click on it

You can think of FBGenericMenu as a branch with leafs inside. The FBGenericMenuItems are leafs. And with FBMenuManager() you can construct, edit and destruct more branches and leafs.

You can create leafs with FBGenericMenu, but that’s all you should use it for (when creating menus).

All main menus are FBGenericMenu instances, the ones that are besides File, Edit, Help, etc.

But here’s the important trick. If you want a submenu inside a menu you need to use FBMenuManager and specify the full path (FBGenericMenu/FBGenericMenuItem) for the new subMenu. It will then create a FBGenericMenu for your FBGenericMenuItem. Confusing? Yes.

One practical example. Say you have a menu called MyTool, and you want a submenu Import with items Animation and Character, something like:

  • MyTool
    • Import
      • Animation
      • Character

You could use this code:

oMenuMngr = FBMenuManager()

oMenuMngr.InsertLast( None, "MyTool" )
oMenuMngr.InsertLast( "MyTool", "Import" )

oMenu = oMenuMngr.GetMenu( "MyTool" )
oMenuItem = oMenu.GetFirstItem()
print oMenuItem.Caption
# Import

oMenuMngr.InsertLast( "MyTool/Import", "Animation" )
# now Import is also a FBGenericMenu as well as a FBGenericMenuItem

temp = oMenu.GetFirstItem()
print temp
# Import FBGenericMenuItem

temp = oMenuMngr.GetMenu( "MyTool/Import")
print temp
# Import FBGenericMenu

Apparently, to get a FBGenericMenu object you need the full path. The FBGenericMenuItems you can get only from the parent FBGenericMenu where it belongs.

FBGenericMenu also holds two important things:

1) a list of Ids, one integer for each FBGenereicMenuItem inside, which doesn’t need to be in order
2) OnMenuActivate, which binds all items to only one function that in turn will run each time the user click on any of FBGenericMenuItems inside this FBGenericMenu.

But I will get more to that on another post about creating dynamic menus based on tools you have on disc.

:, , , , , , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!