Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Gotcha Examples
def toggle_parallel_settings( func ):
def _wrapper( *args, **kwargs ):
# Store the initial values.
evaluate_manager = pyfbsdk.FBEvaluateManager()
p_evaluation = evaluate_manager.ParallelEvaluation
p_pipeline = evaluate_manager.ParallelPipeline
p_deformation = evaluate_manager.ParallelDeformation
# Turn them all off
evaluate_manager.ParallelEvaluation = False
evaluate_manager.ParallelPipeline = False
evaluate_manager.ParallelDeformation = False
pyfbsdk.FBSystem().Scene.evaluate( )
# Run the method
results = func( *args, **kwargs )
evaluate_manager.ParallelEvaluation = p_evaluation
evaluate_manager.ParallelPipeline = p_pipeline
evaluate_manager.ParallelDeformation = p_deformation
return results
return _wrapper
def get_prop_value_from_key( self, prop, frame = None ):
Method grabs the property value from the FCurve rather than the property's Data attribute.
Why do we do this?
Because motionbuilder's scene must be evaluated constantly, properties can get out of sync, but usually are
evaluated just prior to the user seeing them in the viewport. Using the pyfbsdk.FBSystem().OnUiIdle callback
is before the evaluation, so we must evaluate to get the property values.
However, evaluating as often as the UIIdle callback is called is dangerous and prone to crashing, so instead
we trust the keys/fcurves in this scenario to give us the proper values.
anim_node = prop.GetAnimationNode( )
# If no anim node, or FCurve on the anim node, we exit
if not anim_node:
return 0
if not anim_node.FCurve:
return 0
if frame:
# Convert it to FBTime
current_time = pyfbsdk.FBTime( 0, 0, 0, frame )
current_time = pyfbsdk.FBSystem().Scene.LocalTime
# Get the value from the FCurve at that time
value = anim_node.FCurve.Evaluate( current_time )
return value
objects = [ ] # List of objects you want to delete
unable_to_process = [ ]
# Convert the object to a list if the object isn't a list or tuple
if not isinstance( objects, ( set, tuple, list ) ):
objects = [ objects ]
# Iterate through he list and disconnect/delete
for obj in objects:
assert isinstance( obj, pyfbsdk.FBPlug )
if self.is_obj_unbound( obj ): # Check to be sure this object isn't unbound, if it is you don't want to touch it.
if not obj.GetObjectFlags() & pyfbsdk.FBObjectFlag.kFBFlagDeletable:
unable_to_process.append( obj.LongName )
obj.BeginChange( )
if disconnect_dst:
dst_objects = [ ]
# Disconnect all Dst objects except for the Scene component.
for i in range( 0, obj.GetDstCount( ) - 1 ):
dst_objects.append( obj.GetDst( i ) )
for dst_object in dst_objects:
if not isinstance( dst_object, pyfbsdk.FBScene ):
obj.DisconnectDst( dst_object )
if disconnect_src:
obj.DisconnectAllSrc( )
obj.FBDelete( )
coxevan commented Mar 23, 2017

Some of these methods could probably be optimized or made to be better/more flexible but the practices above have worked well for me in the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment