- MotionBuilder Python Script11 -
- MotionBuilder Python Tools - Ren
- MotionBuilder Python Script18 -
- MotionBuilder Python Script17 -
- MotionBuilder Python Script08 -
- MotionBuilder Python Script09 -
- MotionBuilder Python Script10 -
- MotionBuilder Python Script14 -
- MotionBuilder Python Script13 -
- MotionBuilder Python Script12 -
周末了,放个假休息休息,就再来更新一篇!
之前介绍的脚本以"脚本的感觉"来实现的,今天我们来介绍一下"系统级别"的脚本!
一、FBMenu
Menu菜单基本位于软件的顶层显示,通常以下拉菜单的形式呈现
我们来看一下UI效果
FBMenu.gif
这里展示了执行脚本之后,在MoBu的菜单栏上方会出现 New Menu的选项,其中包含了两个选项,以及一个下拉列表 ,我们来看一下官方代码:
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"
比较有用,大家可以好好看一看,decomposition and refactor!
二、结语
有什么问题可以留言!
继续!
共勉!
网友评论