Running Python Scripts

You can run Python scripts when MotionBuilder starts up and while MotionBuilder is running.

Running Python Scripts at Start Up

At start up, MotionBuilder runs Python scripts in the following order:

  1. in <yourinstallationfolder>\bin\config\Python\ The Python Tool Manager stores a list of all custom tools that you create using Python. For more information, see Managing Python Tools.
  2. Python scripts in the user folder. For example, C:\Users\<username>\Documents\MB\<year>-x64\config\PythonStartup)
  3. Python scripts in <yourinstallationfolder>\bin\config\PythonStartup
  4. Python scripts in a user defined Python startup folder. To set the user defined Python startup folder, select Settings Preferences Python, and specify a folder in the Python startup folder field.
NOTE:Do not specify a system folder like <yourinstallationfolder>\bin\config\Scripts\UI as the Python startup folder. Some scripts in these folders might not work during start up and can crash MotionBuilder. It is a best practice to create your own folder to save scripts and specify it as the Python startup folder.

The startup folder is added to the Python import path variable (sys.path). You can import functionality from scripts saved here to other scripts. Alternatively, you can also use the Command Line Options to specify which script to run when MotionBuilder starts up.

Executing Python Programs while MotionBuilder is Running

You can run Python scripts within MotionBuilder in the following ways:

  • Run individual commands and Python scripts in the Python Editor's interactive console, or using the Python Telnet Console.

  • Bind Python scripts to a keyboard shortcut. For more information, see Managing Python Tools.
  • Run Python scripts from the Asset Browser using a custom path (right click in the navigation tree). When you drag and drop from the Asset Browser to the scene, you are prompted to execute, add to the scene, or both. Adding to the scene makes it accessible in the Navigator under Scripts.
  • Run Python scripts through MotionBuilder's C++ API function FBApplication::ExecuteScript().