UI/FBMenu.py

# 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

gMenuMgr = FBMenuManager()

# --------------------------- "File/CustomFileIO" -----------------------------
# Inserts an item inside the File menu.
gMenuMgr.InsertFirst("File", "CustomFileIO")

# Inserts three 'sub-items' under the newly created menu item File/CustomFileIO.
lFileIO1 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 1")
lFileIO2 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 2")
lFileIO3 = gMenuMgr.InsertLast("File/CustomFileIO", "Operation 3")

# Removes the third sub-item.
lCustomFileIOMenu = gMenuMgr.GetMenu( "File/CustomFileIO" )
lCustomFileIOMenu.DeleteItem( lFileIO3 )

# ------------------------------- "New Menu" ----------------------------------
# Inserts a new menu in the topmost menu bar (Set pMenuPath=None to add menu at topmost level).
gMenuMgr.InsertFirst(None, "New Menu")
lNewMenu = gMenuMgr.GetMenu("New Menu")
lNewMenu.InsertLast("Fancy operation 1", 11)
lNewMenu.InsertLast("Fancy operation 2", 12)

# Registers event handler.
lNewMenu.OnMenuActivate.Add(eventMenu)

# Creates a new embedded menu.
lSubMenu = FBGenericMenu()
lSubMenu.InsertFirst("Three", 3)
lSubMenu.InsertFirst("Two", 2)
lSubMenu.InsertFirst("One", 1)
lSubMenu.OnMenuActivate.Add(eventMenu)

# Inserts the embdded menu in the New Menu
lNewMenu.InsertLast("An embedded Menu", 101, lSubMenu)

# --------------------------- "Add menu before/after" ---------------------------
gMenuMgr.InsertBefore(None, "Help", "Before Help")
gMenuMgr.InsertAfter(None, "Help", "After Help")

# ------------------------------- "Pop-up menu" ---------------------------------
lItem = lSubMenu.Execute(100, 200)
if lItem:
    print "Pop-up menu: Selected item = %s.\n" % lItem.Caption
else:
    print "Pop-up menu: No item selected.\n"