Set the standard of arranging original Python Tools/Scripts
In the Menubar, add new menu to invoke original Scripts/Tools
set the following directories in Users/<username>/Documents/MB/<version>/config/PythonStartup
folder.
Tools
: Python Tools registered in FBToolsScripts
: Python Scripts which can be used as module
Put data under src
folder into C:/Users/<username>/Documents/MB/<version>/config/PythonStartup
directory
define main()
function to execute all functions in the module
In the main file, define ActivateTool()
function below
def ActivateTool():
# define the Tool name
toolName = "<tool name>"
# check the Tool already created
if toolName in FBToolList:
ShowToolByName(toolName)
else:
# declare tool
tool = <Original Tool Class declare>
FBAddTool(tool)
ShowToolByName(toolName)
pyfbsdk.FBGetmainWindow() can return the MotionBuilder main window.
One of the child widget contains MenuBar, to which add new menu.
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
extracts module name from Tools/Scripts path.
mbar = getMenubar()
tmenu = mbar.addMenu("Tools")
smenu = mbar.addMenu("Scripts")
# if Tools
for file in os.listdir(<toolpath>):
if file.endswith(".py"):
# extract module name to import
module_name = file[:-3]
module = importlib.import_module(module_name)
# add action to invoke tool function
t = tmenu.addAction(module_name)
t.triggered.connect(module.ActivateTool)
# if Scripts
for file in os.listdir(<scriptpath>):
if file.endswith(".py"):
# extract module name to import
module_name = file[:-3]
module = importlib.import_module(module_name)
# add action to invoke tool function
s = smenu.addAction(module_name)
s.triggered.connect(module.main)