Python Scripting in MotionBuilder

03 – Components and the Scene

Part Three dives into the major concepts necessary to understand how the scene is put together, and the common functionality inherent in all scene objects.

Watch on YouTube | Watch in a full window

Key Points


Code

Query selection state, select, and deselect

print cube.Selected
cube.Selected = True
cube.Selected = False

Get and set name and long name

cube.LongName = 'alpha:bravo:Cube'
print cube.LongName  # prints 'alpha:bravo:Cube'
print cube.Name      # prints 'Cube'
cube.Name = 'Kubus'
print cube.LongName  # prints 'alpha:bravo:Kubus'

Add a namespace to a model and its branches, then change that namespace

cube.ProcessNamespaceHierarchy(
    FBNamespaceAction.kFBConcatNamespace, 'OLD')
cube.ProcessNamespaceHierarchy(
    FBNamespaceAction.kFBReplaceNamespace, 'OLD', 'NEW')

Find a property by name and set its value

cube.PropertyList.Find('Show').Data = True
cube.Show = True # <-- equivalent

Modify a vector property

cube.Translation = FBVector3d(0.0, 5.0, 0.0)

Get, modify, and set a model's transformation matrix

m = FBMatrix(); cube.GetMatrix(m)
for i in (4, 5, 6):
    m[i] *= 2.0 # Double the Y-scale
m[13] += 5.0 # Move up along global Y by 5 units
cube.SetMatrix(m)

Parent one model to another

''' If parentModel were already childModel's Parent, setting it so would
instead UNparent it (for some reason). In lieu of this check, we could also
set childModel.Parent = None before proceeding. '''
if childModel.Parent != parentModel:
    childModel.Parent = parentModel

Notes & Errata

The Maya Analogy

Around 0:50, I make a comparison between MotionBuilder's components and Maya's nodes. This comparison is apt in that components and nodes are the most basic object type in their respective applications, but they're not exactly equivalent.

Most importantly, Maya's nodes implement functionality which in MotionBuilder is delegated to multiple classes, primarily FBBox in addition to FBComponent. Whereas Maya uses groups of multiple nodes to represent complex objects, MotionBuilder implements specialized object types by way of inheritance.


Source and Destination Connections

A similar caveat: At 0:54, when you see the depiction of the source and destination relationships that connect all the components in the scene, you may be reminded of Maya's Hypergraph editor, where the lines running between objects represent the lazily-evaluated flow of animation data for specific properties. This is not what source and destination connections do.

MotionBuilder has a very similar system for evaluating animation data in real-time, but it's done (roughly speaking) on a property-to-property basis rather than a component-to-component basis. As we'll get into later on, real-time evaluation of properties involves animation nodes which belong to FBBox objects. FBComponents themselves do not deal with animation.

Source and destination connections only describe relationships between components — they don't convey any data. MotionBuilder manages them transparently, and you should never need to worry about modifying them yourself.


Corrections?

If you see any errors that you'd like to point out, feel free to email me at awforsythe@gmail.com.