Original Mobu Python Scripts for daily use
Create Tools
and Scripts
Folder and stor PluginBase.py
in the Python Startup Folder.
Tools
: Folder for tools which will be stored in FBToolListScripts
: Folder for simple scritpsPluginBase.py
: Imported by Mobu System, then create Menu and associate scripts with it
The following image shows how to arrange them.
These modules can be installed automatically using Installer/PluginBase_Setup.exe
.
Note: For Windows only
- The tool name must be identical to its module.
- Do not show tool, just create and add to FBToolList using
FBAddTool()
pyfbsdk.FBGetmainWindow() returns the pointer to the MotionBuilder's Mainwindow.
One of the child widget of the Mainwindow is that Menubar.
def getMenubar() -> QMenuBar:
# get Main Window
pMainW = FBGetMainWindow()
if pMainW:
#Convert pointer to any non-inappropriate type
MainW = wrapInstance(pMainW, QMainWindow)
menubar = MainW.menuWidget().children()[1]
return menubar
PluginBase.py
creates a Menu and associate scripts with it.
Note that QtGui.QAction.triggered()
has checked
bool parameter.
mbar = getMenubar()
tmenu = mbar.addMenu("Tools")
smenu = mbar.addMenu("Scripts")
# if tools
for tools_filepath in tools_dir.iterdir():
if str(tools_filepath).endswith(".py"):
FBApplication().ExecuteScript(str(tools_filepath))
# add submenu
module_name = tools_filepath.stem
t = tmenu.addAction(module_name)
t.triggered.connect(lambda checked=False, name=module_name : ShowToolByName(name))
# if scripts
for script_filepath in scripts_dir.iterdir():
if str(script_filepath).endswith(".py"):
s = smenu.addAction(script_filepath.stem)
s.triggered.connect(lambda checked=False, sp = str(script_filepath) : FBApplication().ExecuteScript(sp))