Python Scripting Reference Guide (pyfbsdk)

Python Scripting Reference Guide (pyfbsdk)

Introduction to Python Scripting

This section lists the classes and methods in Python that you can use for scripting in MotionBuilder.

Python Scripting in MotionBuilder

MotionBuilder has a Python Editor and Python interpreter. You can write and run Python scripts from within MotionBuilder. You can use Python to customize MotionBuilder and for automating repetitive tasks.

Only a subset of the existing C++ Open Reality SDK is exposed to Python using an almost identical class hierarchy. Some Python specific enhancements and additions are made in the exposed subset of the Open Reality SDK. See the pyfbsdk_additions.py file located in <yourinstallationfolder>. You might not be able to perform certain tasks because the necessary classes might not be available in the exposed subset.

You can refer to the What�s New section for information about the new features and changes related to Python.

Requirements

You do not have to install any additional software for scripting in Python. MotionBuilder includes a minimal Python environment. If you have installed Python version 2.7.3, it is automatically used for running scripts in MotionBuilder.

Limitations and Restrictions

Python has the same limitations as the C++ Open Reality SDK because it is an exposed subset of the C++ Open Reality SDK. Additionally, the Python module has the following restrictions:

  • The only way to run Python from C++ is by using the FBApplication::ExecuteScript function to call the Python modules. For more information, see the FBApplication class reference in the SDK help.
  • Python classes cannot serve as a parent to a client class because the inherited virtual methods cannot be overloaded.
  • You cannot set certain enum flags that are exposed in Python. These are reserved flags and cannot be triggered. For example in the FBPlugModificationFlag enum, the kFBSelfDataModified, kFBSelfKeyingModified, and kFBContentKeyingModified flags cannot be triggered when they are passed as a pModificationFlags parameter in the NamespaceGetContentList function of the FBScene class.

Custom Modules

To use a custom Python module, copy your modules to <yourinstallationfolder>/bin/<platform>/python/lib. You can copy the binary modules, such as .pyd for Windows to <yourinstallationfolder>/bin/<platform>/python/lib/plat-win.

If you prefer a different set up, you can modify the PYTHONPATH and PATH environment variables. Please refer to the Python documentation for more information.

Class Type

You can determine if an object is of a certain class type by using the function Is(int pTypeId) in the FBPlug class. The parameter pTypeId is a FBClassName_TypeInfo() function that is defined in each class exposed to Python. You can replace ClassName with a class name to determine the class type of the object.

For example:

cube.Is(FBComponent_TypeInfo()) returns True

FBSystem().Is(FBModel_TypeInfo()) returns False

Default Parameter

If a class constructor has one or more default parameters, you must specify them when calling the constructor.

Documentation and Feedback

Warning
The Python documentation is automatically generated from the Open Reality C++ SDK documentation. If there are any errors, omissions, or inconsistencies, you can report them to ensure that it is corrected. For contact and feedback information, refer to the Information and Technical Support topic in the SDK help.

Distribution

Resources

The Open Reality distribution consists of the following:

  • Python Scripting Reference Guide (pyfbsdk)
  • Python Scripting Sample Scripts