# Copyright 2009 Autodesk, Inc. All rights reserved. # Use of this software is subject to the terms of the Autodesk license agreement # provided at the time of installation or download, or which otherwise accompanies # this software in either electronic or hard copy form. # # Script description: # Shows how to inserts and modify MoBu menus. Shows also how to create a pop-up menu. # # Topic: FBMenuManager, FBGenericMenu, FBGenericMenuItem # from pyfbsdk import * # This function just prints the infos of the menu that has been clicked. def eventMenu(control, event): print control, event.Id, event.Name menuMgr = FBMenuManager() # Inserts an item inside the File menu. item = menuMgr.InsertFirst("&File", "test") # All FBMenuManager method to inserts new menu takes a menu path as the point of insertion. # a menu path specifies where in the menu hierarchy to insert the menu. You have to use / as separator # between menus for insertion. new_keyboard_item = menuMgr.InsertFirst("&Settings/&Keyboard Configuration", "New keyboard") # As a rule of thumb, since a lot of menu items have an accelrator bound to them this # means the name of the item contains a "&". Generally the "&" is the first letter of # the item. Here is the list of names of all "root" menu items in MoBu: # "&File", "&Edit","&Animation","&Window","&Settings", "&Layout","&Help" # Inserts a new root menu in the menu bar (notice how we pass None as the # menu path when we deal with root menu). item2 = menuMgr.InsertFirst(None, "New Menu") # Get the menu corresponding to the newly inserted menu. menu = menuMgr.GetMenu("New Menu") menu.InsertLast("foo", 11) menu.InsertLast("bar", 12) menu.InsertLast("foin", 13) # register our menu handler menu.OnMenuActivate.Add(eventMenu) # create a new embedded menu. insideMenu = FBGenericMenu() insideMenu.InsertFirst("One", 1) insideMenu.InsertFirst("Two", 2) insideMenu.InsertFirst("Three", 3) insideMenu.OnMenuActivate.Add(eventMenu) # iterator over these items: item = insideMenu.GetFirstItem() while item: print item.Name item = insideMenu.GetNextItem(item) # inserts the embdded menu in the New Menu menu.InsertLast("An embedded Menu", 101, insideMenu) # Inserts 2 new menus before and after the Help menu (notice how we pass None as # menu path when we deal with root menu). menuMgr.InsertBefore(None, "&Help", "before") menuMgr.InsertAfter(None, "&Help", "after") # You can also use a FBGenericMenu as a pop-up menu. To do so you have to # use the Execute method to pop it. The return value of this method is the menu item # that was clicked: item = insideMenu.Execute(100, 200) if item: print item.Name else: print "user clicked outside!"