【MotionBuilder Script】でボタンやトグルの作成
2019-12-09
MotionBuildernのPythonスクリプトで様々なボタンを実装する方法.完全メモ書きなので適宜Pythonスクリプト内に組み込むこと.コメントアウトには日本語は使えない.
Env.
- windows10 64bit
- MotionBuilder2018
e.g.
ベーシックなボタン
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from pyfbsdk import * from pyfbsdk_additions import * # Callback def BtnCallback(control, event): print control.Caption, " has been clicked!" # Layout def PopulateLayout(mainLyt): x = FBAddRegionParam(0, FBAttachType.kFBAttachLeft, "") y = FBAddRegionParam(0, FBAttachType.kFBAttachTop, "") w = FBAddRegionParam(0, FBAttachType.kFBAttachRight, "") h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "") mainLyt.AddRegion("main", "main", x, y, w, h) lyt = FBHBoxLayout() mainLyt.SetControl("main", lyt) # ============== MAIN SECTION START ======== b = FBButton() b.Caption = "BasicButton" # Button Text b.Justify = FBTextJustify.kFBTextJustifyLeft # Left justified lyt.Add(b, 100) # set width b.OnClick.Add(BtnCallback) # Add Callback # ============== MAIN SECTION END ======== def CreateTool(): t = FBCreateUniqueTool("Basic Button eg") t.StartSizeX = 100 t.StartSizeY = 100 PopulateLayout(t) ShowTool(t) CreateTool() |
色が変わるボタン
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from pyfbsdk import * from pyfbsdk_additions import * # Callback def BtnCallback(control, event): print "Button State :", control.State # Layout def PopulateLayout(mainLyt): x = FBAddRegionParam(20, FBAttachType.kFBAttachLeft, "") y = FBAddRegionParam(40, FBAttachType.kFBAttachTop, "") w = FBAddRegionParam(0, FBAttachType.kFBAttachRight, "") h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "") mainLyt.AddRegion("main", "main", x, y, w, h) lyt = FBHBoxLayout() mainLyt.SetControl("main", lyt) # ============== MAIN SECTION START ======== b = FBButton() b.Caption = "ON-OFF Button" b.Style = FBButtonStyle.kFB2States b.Look = FBButtonLook.kFBLookColorChange b.Justify = FBTextJustify.kFBTextJustifyCenter # Center Justifiy b.SetStateColor(FBButtonState.kFBButtonState0, FBColor(0.5, 0.5, 0.5)) b.SetStateColor(FBButtonState.kFBButtonState1, FBColor(0.0, 1.0, 0.0)) lyt.Add(b, 100) b.OnClick.Add(BtnCallback) # ============== MAIN SECTION END ======== def CreateTool(): t = FBCreateUniqueTool("On Off Button eg") t.StartSizeX = 100 t.StartSizeY = 100 PopulateLayout(t) ShowTool(t) CreateTool() |
画像付きボタン
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from pyfbsdk import * from pyfbsdk_additions import * # Callback def BtnCallback(control, event): print "Button State :", control.State # Layout def PopulateLayout(mainLyt): x = FBAddRegionParam(20, FBAttachType.kFBAttachLeft, "") y = FBAddRegionParam(40, FBAttachType.kFBAttachTop, "") w = FBAddRegionParam(0, FBAttachType.kFBAttachRight, "") h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "") mainLyt.AddRegion("main", "main", x, y, w, h) lyt = FBHBoxLayout() mainLyt.SetControl("main", lyt) # ============== MAIN SECTION END ======== b = FBButton() b.Caption = "Img Button" b.Style = FBButtonStyle.kFBBitmap2States b.Look = FBButtonLook.kFBLookNormal b.Justify = FBTextJustify.kFBTextJustifyCenter b.SetImageFileNames("tape/tape_still_on.png", "tape/tape_play_on.png") lyt.Add(b, 60) b.OnClick.Add(BtnCallback) # ============== MAIN SECTION START ======== def CreateTool(): t = FBCreateUniqueTool("Img Button eg") t.StartSizeX = 100 t.StartSizeY = 100 PopulateLayout(t) ShowTool(t) CreateTool() |
チェックマークボックス
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from pyfbsdk import * from pyfbsdk_additions import * # Callback def BtnCallback(control, event): print "Button State :", control.State # Layout def PopulateLayout(mainLyt): x = FBAddRegionParam(20, FBAttachType.kFBAttachLeft, "") y = FBAddRegionParam(30, FBAttachType.kFBAttachTop, "") w = FBAddRegionParam(0, FBAttachType.kFBAttachRight, "") h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "") mainLyt.AddRegion("main", "main", x, y, w, h) lyt = FBHBoxLayout() mainLyt.SetControl("main", lyt) # ============== MAIN SECTION START ======== b = FBButton() b.Caption = "Test" b.Style = FBButtonStyle.kFBCheckbox b.Justify = FBTextJustify.kFBTextJustifyCenter lyt.Add(b, 60) b.State = True b.OnClick.Add(BtnCallback) # ============== MAIN SECTION END ======== def CreateTool(): t = FBCreateUniqueTool("Check Box eg") t.StartSizeX = 100 t.StartSizeY = 100 PopulateLayout(t) ShowTool(t) CreateTool() |