FBComponent - The Base Entity Class
 
 
 

Memory Management

The FBComponent class can be viewed as the base entity class for the MotionBuilder SDK. It defines the basic memory management methods for object creation and destruction. The following Python sample illustrates how to create and destroy an instance of FBModelCube (a subclass of FBComponent).

from pyfbsdk import *

# A cube is created in the scene with a name 'Cube'.
cube = FBModelCube('Cube')

# ...

# The cube is destroyed.
cube.FBDelete()
NoteCalling FBModelCube('Cube') in succession will create cubes named Cube, Cube 1, Cube 2, Cube 3, etc. The following subsection describes the use of names and namespaces in greater detail.

Names and Namespaces

An FBComponent can be uniquely identified by the combination of two strings: a namespace and a name. The FBComponent.LongName property returns these two strings in the following format: "Namespace:Name". The FBComponent.Name property returns the name of the component without its namespace.

Namespaces can be used to facilitate object organization. For example, a namespace can be assigned to the various body parts (FBModel) of a character (FBCharacter) in the scene. This lets you identify the character to which a body part belongs. In the following image, PlasticMan:Hips refers to the hips of the PlasticMan character, identified by the PlasticMan namespace.

Searching

Component names can be used for searching. In the following Python sample, a regular expression pattern is used to match the name of a newly created cube in the scene.

from pyfbsdk import *

# Create a cube in the scene with the name 'placeholder' 
cube = FBModelCube('placeholder')

# We replace the cube's name with 'TestCube', to illustrate the
# use of the FBComponent.Name property.
cube.Name = 'TestCube'

# Initialize an empty FBComponent list. This list will contain the search
# results after we have called FBFindObjectsByName().
cl = FBComponentList()

# We are going to look for objects which end in 'Cube'. In the following
# pattern, the '*' is a wildcard. This pattern will match the string 'TestCube'.
pattern = '*Cube'

# FBFindObjectsByName() Parameters:
#    pattern - The pattern we are looking for in the object name.
#    cl - The list which will contain the search results.
#    False - We do not wish to include the namespace in our search.
#    True - We are only looking for instances of FBModel (which is a subclass of FBComponent)
FBFindObjectsByName(pattern, cl, False, True)

# The following line prints "Objects found: 1".
print "Objects found: " + str(len(cl))

# Delete the cube from the scene.
cube.FBDelete()

# Re-initialize the cl variable with an empty component list, and run FBFindObjectsByName() again.
cl = FBComponentList()
FBFindObjectsByName(pattern, cl, False, True)

# The following line indicates that no objects are found after the cube's deletion.
print "Objects found after cube deletion:" + str(len(cl))

For more information, consult the BasicOperations/FindObjectsWithWildcard.py sample as well as the pyfbsdk.FBFindObjectsByName() documentation.

Properties

Each instance of FBComponent contains a list of properties (FBProperty), accessible via FBComponent.PropertyList. Properties are used to specify an object's data attributes such as the translation, rotation and scaling information of a cube. For more information, see FBProperty - Object Properties.

The following Python program prints the name and data of each property for a newly created cube (FBModel). The try/except block within the for loop lets the program continue its execution if str(p.Data) causes an exception due to the lack of a string representation.

from pyfbsdk import *

cube = FBModelCube('Cube')
propertyList = cube.PropertyList
for p in propertyList:
    try:
        print 'Name: "' + p.Name + '", Data: [' + str(p.Data) + ']'
    except Exception:
        pass

cube.FBDelete()

NoteFBComponent and FBProperty both inherit from FBPlug. This inheritance allows instances of FBComponent and FBProperty to connect with one another at runtime. For more information, consult the FBPlug - Object Connection Management topic.