Skip to content

Instantly share code, notes, and snippets.

@Danlowlows
Last active September 24, 2019 09:45
Show Gist options
  • Save Danlowlows/7c717ae0d3b9a4660556a3aebcafcb12 to your computer and use it in GitHub Desktop.
Save Danlowlows/7c717ae0d3b9a4660556a3aebcafcb12 to your computer and use it in GitHub Desktop.
Example script for adding new menus to the toolbar in Motionbuilder.
"""
Example script for adding new menus to the toolbar in Motionbuilder.
Created by Dan Lowe - [ 5th April 2018 ] - (@Danlowlows on Twitter)
"""
# Import all your different scripts from different files.
from pyfbsdk import FBMenuManager, FBMessageBox
from DamnFineSeamanship.BoatStuff import RaiseMizzenmast
from DamnFineSeamanship.BoatStuff import JibbTopsails
from Games.Galaga import PlayGalaga
# For each function, create an event check that matches the name of the event to the function you want to call.
def OnMenuClick(eventName):
if eventName == "Raise the mizzenmast":
RaiseMizzenmast()
elif eventName == "Jibb the topsails":
JibbTopsails()
elif eventName == "Play Galaga":
PlayGalaga()
else:
FBMessageBox("Error...", "Menu Error: This option hasn't been set up yet. Please contact your friendly neighbourhood Technical Animator", "OK")
# This bit of the script creates the menu. Make sure to add menu options for any new events that you add. The name of the menu will be the eventName so they need to be the same.
def LoadMenu():
def MenuOptions(control, event):
eventName = event.Name
OnMenuClick(eventName)
mainMenuName = "Example Menu"
menuManager = FBMenuManager()
menuManager.InsertLast( None, mainMenuName )
menuManager.InsertLast( mainMenuName, "Seamanship" ) # I'm adding sub-menus here, but you could add a menu option to the first level of the menu by replacing "Seamanship" with the name of the menu/event.
menuManager.InsertLast( mainMenuName, "" ) # This creates a line break
menuManager.InsertLast( mainMenuName, "Games" )
menuManager.InsertLast( mainMenuName + "/Seamanship", "Raise the mizzenmast" )
menuManager.InsertLast( mainMenuName + "/Seamanship", "Jibb the topsails" )
menuManager.InsertLast( mainMenuName + "/Games", "Play Galaga" )
# And then this bit of the script adds the created menu to the Mobu tool bar.
def AddMenu(mainMenuName, subMenuName = ""):
menu = FBMenuManager().GetMenu( mainMenuName + subMenuName)
if menu:
menu.OnMenuActivate.Add( MenuOptions )
AddMenu(mainMenuName)
AddMenu(mainMenuName + "/Seamanship")
AddMenu(mainMenuName + "/Games")
# This runs everything, or you can drop the script somewhere in your tools folder and just call LoadMenu() in the Mobu startup script.
LoadMenu()
@alexdjulin
Copy link

Thanks, works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment