美文网首页工具癖
MotionBuilder Python Script11 -

MotionBuilder Python Script11 -

作者: Houdinini | 来源:发表于2019-07-27 11:06 被阅读16次
neng屎所有人,就没有人发现我潜入了

周末了,放个假休息休息,就再来更新一篇!

之前介绍的脚本以"脚本的感觉"来实现的,今天我们来介绍一下"系统级别"的脚本!

一、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!

二、结语

有什么问题可以留言!

继续!

共勉!

相关文章

网友评论

    本文标题:MotionBuilder Python Script11 -

    本文链接:https://www.haomeiwen.com/subject/bvvsrctx.html