UI/FBMenu.py

UI/FBMenu.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Shows how to inserts and modify MoBu menus. Shows also how to create a pop-up menu.
8 #
9 # Topic: FBMenuManager, FBGenericMenu, FBGenericMenuItem
10 #
11 
12 from pyfbsdk import *
13 
14 # This function just prints the infos of the menu that has been clicked.
15 def eventMenu(control, event):
16  print control, event.Id, event.Name
17 
18 gMenuMgr = FBMenuManager()
19 
20 # --------------------------- "File/CustomFileIO" -----------------------------
21 # Inserts an item inside the File menu.
22 gMenuMgr.InsertFirst("File", "CustomFileIO")
23 
24 # Inserts three 'sub-items' under the newly created menu item File/CustomFileIO.
25 lFileIO1 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 1")
26 lFileIO2 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 2")
27 lFileIO3 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 3")
28 
29 # Removes the third sub-item.
30 lCustomFileIOMenu = gMenuMgr.GetMenu( "File/CustomFileIO" )
31 lCustomFileIOMenu.DeleteItem( lFileIO3 )
32 
33 # ------------------------------- "New Menu" ----------------------------------
34 # Inserts a new menu in the topmost menu bar (Set pMenuPath=None to add menu at topmost level).
35 gMenuMgr.InsertFirst(None, "New Menu")
36 lNewMenu = gMenuMgr.GetMenu("New Menu")
37 lNewMenu.InsertLast("Fancy operation 1", 11)
38 lNewMenu.InsertLast("Fancy operation 2", 12)
39 
40 # Registers event handler.
41 lNewMenu.OnMenuActivate.Add(eventMenu)
42 
43 # Creates a new embedded menu.
44 lSubMenu = FBGenericMenu()
45 lSubMenu.InsertFirst("Three", 3)
46 lSubMenu.InsertFirst("Two", 2)
47 lSubMenu.InsertFirst("One", 1)
48 lSubMenu.OnMenuActivate.Add(eventMenu)
49 
50 # Inserts the embdded menu in the New Menu
51 lNewMenu.InsertLast("An embedded Menu", 101, lSubMenu)
52 
53 # --------------------------- "Add menu before/after" ---------------------------
54 gMenuMgr.InsertBefore(None, "Help", "Before Help")
55 gMenuMgr.InsertAfter(None, "Help", "After Help")
56 
57 # ------------------------------- "Pop-up menu" ---------------------------------
58 lItem = lSubMenu.Execute(100, 200)
59 if lItem:
60  print "Pop-up menu: Selected item = %s.\n" % lItem.Caption
61 else:
62  print "Pop-up menu: No item selected.\n"
63