Plotting selected properties using MotionBuilder’s Python.


I ran the script I created in “Animating and setting keys with MotionBuilder’s Python Editor” and decided that I would use the scene it creates to learn how to plot on selected properties in MotionBuilder’s Python Editor.

Update:

I found a work around for the bug and it is covered in my “lock-and-plot-selected-properties-using-motionbuilders-python” post.

Original post below:


BUG NOTE:

I started to write this post with a clear idea in my mind – Animate the Translation, Rotation and Scale of an object using Python and then have the Translation curves be plotted with Plot Selected Properties.

MotionBuilder 2015 seems to have a bug with Plotting selected properties. It seems that Translation and Rotation are coupled when using Plot Selected Properties. The easiest way I can reproduce this bug is through the following steps in MotionBuilder 2015:

  • Create a marker
  • Set a key on frame 0
  • Move to another frame
  • Translate the marker and set a key
  • In either the FCurve editor or the  properties window select the x axis of the translation only
  • Under key controls select Animation -> Plot Selected (Selected Properties)

I would expect that only the X axis of the translation gets plotted (or even just Translation), but we get all of Translation and Rotation plotted while Scale remains untouched.

If I was to go into Key Controls and choose “Selected Properties” from the drop down and then reproduce the above mentioned steps we would get Translation and Rotation curves to separate from each other when plotting.

The Translation’s 3 axis are still not referenced to or processed as separate curves – so no plotting on just the X axis. 🙁

I am still going to show the code below here because there is still some interesting things learned when writing it.


To follow this post you should run the script that was created for “Animating and setting keys with MotionBuilder’s Python Editor” or you can download the final Python script here.

OK, now that the Python script mentioned above has been executed into your MotionBuilder scene it’s now time to move onward to Plotting selected properties using MotionBuilder’s Python.

A NOTE ON GETTING THE SCRIPT TO WORK CORRECTLY:

To get the script to run properly you need to set the Key Mode to “Selected Properties” within your Key Controls before running the code below.

I am researching a way to have Python tell MotionBuilder to set the Key Mode to “Selected Properties”, as of right now it looks as if “Key Mode” is only available for the CharacterControls (FullBody, BodyPart, etc.).

Selecting properties to plot on:

from pyfbsdk import *

'''
Here is where we will start the attempt to plot on selected properties

First we are going to animate the rotation and the scaling - this will have animation on all 3 transforms
'''

# Define the Transaltion to be represented as lmarker.Translation
xTrans, yTrans, zTrans = lmarker.Translation
# Define the Rotation to be represented as lmarker.Rotation
xRot, yRot, zRot = lmarker.Rotation
# Define the Scale to be represented as lmarker.Rotation
xScl, yScl, zScl = lmarker.Scaling

# Declare that lmarker.Translation, lmarker.Rotation and lmarker.Scale can be animated
lmarker.Translation.SetAnimated(True)
lmarker.Rotation.SetAnimated(True)
lmarker.Scaling.SetAnimated(True)

# Rotate lmarker.Rotation to 0 on the x axis, 0 on the y axis and 0 on the z axis [0, 0, 0]
# Set a key at frame 0 (FBTime(0,0,0,0) - the time is the last 0 in the sequence
lmarker.Rotation.GetAnimationNode().KeyAdd(FBTime(0,0,0,0), [0, 0, 0])

# Rotate lmarker.Rotation to 3600 on the x, y and z axis [3600, 3600, 3600].
# I picked 3600 so that we can really see the result
# Set a key at frame 200 (FBTime(0,0,0,200) - the time is the last 0 in the sequence
lmarker.Rotation.GetAnimationNode().KeyAdd(FBTime(0,0,0,200), [3600, 3600, 3600])

# Scale lmarker.Scaling to 0 on the x axis, 0 on the y axis and 0 on the z axis [0, 0, 0]
lmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,0), [1, 1, 1])

# Scale lmarker.Scaling to 10 on the x, y and z axis [10, 10, 10].
# Set a key at frame 200 (FBTime(0,0,0,200) - the time is the last 0 in the sequence
lmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,100), [5, 5, 5])

# Scale lmarker.Scaling to 0 on the x axis, 0 on the y axis and 0 on the z axis [0, 0, 0]
lmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,200), [1, 1, 1])

''' now let's plot only the translation animations and leave the rotation and scaling untouched '''
# Search the objects PropertyList and find "Lcl Translation, Lcl Rotation and Lcl Scaling"
lTranslation = lmarker.PropertyList.Find( 'Lcl Translation' )
lRotation = lmarker.PropertyList.Find( 'Lcl Rotation' )
lScaling = lmarker.PropertyList.Find( 'Lcl Scaling' )

# Select the marker's Translation fcurves using SetFocus
lTranslation.SetFocus(True)
#Ensure the marker's Rotation and Scaling is not selected
lRotation.SetFocus(False)
lScaling.SetFocus(False)

# Plot the Marker's Selected Properties    
FBSystem().CurrentTake.PlotTakeOnSelectedProperties( FBTime(0,0,0,1))

Once the above script is executed we see that the Scale’s curves were untouched when plotting. Unfortunately the bug in MotionBuilder 2015 will not uncouple the Translation and Rotation using Plot Selected Properties.

“PropertyList.Find()” and the “SetFocus()” are the interesting parts of this code:

# Search the objects PropertyList and find "Lcl Translation, Lcl Rotation and Lcl Scaling"
lTranslation = lmarker.PropertyList.Find( 'Lcl Translation' )
lRotation = lmarker.PropertyList.Find( 'Lcl Rotation' )
lScaling = lmarker.PropertyList.Find( 'Lcl Scaling' )

# Select the marker's Translation fcurves using SetFocus
lTranslation.SetFocus(True)
#Ensure the marker's Rotation and Scaling is not selected
lRotation.SetFocus(False)
lScaling.SetFocus(False)

Here is a simple script to demonstrate “PropertyList.Find()” and the “SetFocus()” working together to select a property of an object:

from pyfbsdk import *

# Get the instance of FBApplication, and clear the scene with FileNew().
app = FBApplication()
app.FileNew()

# Creat an object that we will animate
lmarker = FBModelMarker('VicMarker')
lmarker.Show = True
lmarker.Size = 1000
lmarker.PropertyList.Find('LookUI').Data=1
lmarker.Color = FBColor(0,1,1)
lmarker.Selected = True

# Search the objects PropertyList and find "Lcl Translation, Lcl Rotation and Lcl Scaling"
lTranslation = lmarker.PropertyList.Find( 'Lcl Translation' )
lRotation = lmarker.PropertyList.Find( 'Lcl Rotation' )
lScaling = lmarker.PropertyList.Find( 'Lcl Scaling' )

# Set Properties to be Selected
lTranslation.SetFocus(False)
lRotation.SetFocus(True)
lScaling.SetFocus(False)

By playing with the “SetFocus()” values (True or False) and rerunning the script – we see in the FCurve Editor which properties are being selected.

I hope this has helped, I know I learned a lot from this long post.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.