Python Reference Guide
 
Loading...
Searching...
No Matches
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
12from pyfbsdk import *
13
14# This function just prints the infos of the menu that has been clicked.
15def eventMenu(control, event):
16 print(control, event.Id, event.Name)
17
18gMenuMgr = FBMenuManager()
19
20# --------------------------- "File/CustomFileIO" -----------------------------
21# Inserts an item inside the File menu.
22gMenuMgr.InsertFirst("File", "CustomFileIO")
23
24# Inserts three 'sub-items' under the newly created menu item File/CustomFileIO.
25lFileIO1 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 1")
26lFileIO2 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 2")
27lFileIO3 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 3")
28
29# Removes the third sub-item.
30lCustomFileIOMenu = gMenuMgr.GetMenu( "File/CustomFileIO" )
31lCustomFileIOMenu.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).
35gMenuMgr.InsertFirst(None, "New Menu")
36lNewMenu = gMenuMgr.GetMenu("New Menu")
37lNewMenu.InsertLast("Fancy operation 1", 11)
38lNewMenu.InsertLast("Fancy operation 2", 12)
39
40# Registers event handler.
41lNewMenu.OnMenuActivate.Add(eventMenu)
42
43# Creates a new embedded menu.
44lSubMenu = FBGenericMenu()
45lSubMenu.InsertFirst("Three", 3)
46lSubMenu.InsertFirst("Two", 2)
47lSubMenu.InsertFirst("One", 1)
48lSubMenu.OnMenuActivate.Add(eventMenu)
49
50# Inserts the embdded menu in the New Menu
51lNewMenu.InsertLast("An embedded Menu", 101, lSubMenu)
52
53# --------------------------- "Add menu before/after" ---------------------------
54gMenuMgr.InsertBefore(None, "Help", "Before Help")
55gMenuMgr.InsertAfter(None, "Help", "After Help")
56
57# ------------------------------- "Pop-up menu" ---------------------------------
58lItem = lSubMenu.Execute(100, 200)
59if lItem:
60 print("Pop-up menu: Selected item = %s.\n" % lItem.Caption)
61else:
62 print("Pop-up menu: No item selected.\n")
63
A GenericMenu class.
Definition: pyfbsdk_generated.h:8206
The menu manager allows access to MotionBuilder menu bar.
Definition: pyfbsdk_generated.h:10723