Setting up MotionBuilder Relation Constraint

Hello,

I need to setup twist joints (these are leaf joints) in MB using Relation constraints. I know how to set these up manually but hit a wall when doing so through python. Here is a screen grab from the constraint settings of the manual approach:


Notice I’m using a Vector to numbers and a multiply node.

Note: I can already create a relation constraint through Python (seen belwo) but have problems adding the settings. example of the code below:

def create_relation_constraint(self, objParent, objChild, constraint_name, offset = True):
    """
    
    Description: Creates a relation constraint!
    
    """ 
 
    ##Create "Relation" Constraint 
    for i in range( FBConstraintManager().TypeGetCount() ):
        if "Relation" in FBConstraintManager().TypeGetName(i):
            lMyConstraint = FBConstraintManager().TypeCreateConstraint(i)
         
    #for index, element in enumerate(selected_objects):
    #lMyConstraint.ReferenceAdd (0, objChild)
    #lMyConstraint.ReferenceAdd (1, objParent)
     
    #Snap if user desires
    if offset == True:
        lMyConstraint.Snap()
     
    #weight of the constraint
    lMyConstraint.Weight = 100
     
    ##Activate Constraint
    lMyConstraint.Active = True 
    lMyConstraint.Name = "{0}_Relation".format(constraint_name)
    
    return lMyConstraint # Returns FBConstraintRelation

Example of the following commands would really help:

*How to add Sender and Reciever joints. How do you set these to relative and not global.

*How to add and connect the nodes shown in the diagram.

Any help would be great.

Thanks

I’ve managed to solve most of this. Here’s some of the code that does the same as my previous image regarding the nodes and connections:

#Create "Relation" Constraint

constriant_name = "Test_Twist_ConRel"

relation_constraint = FBConstraintRelation(constriant_name)

relation_constraint.Active = True # Turn constraint on!

#Set up driver jnt (it's a box in MB)

src_box = relation_constraint.SetAsSource(scr_jnt)

relation_constraint.SetBoxPosition( src_box, 0, 100 )# Set the box position within the constraint setting graph!

src_box.UseGlobalTransforms = False # makes translation/rotation local "Lcl"

#Set up driven jnt (it's a box in MB)

trgt_box = relation_constraint.ConstrainObject(target_jnt)

relation_constraint.SetBoxPosition( trgt_box, 1200, 100 )

trgt_box.UseGlobalTransforms = False # makes translation/rotation local "Lcl"

# Creates Vector to Number and Multiply (a x b) nodes (these are called boxes)

v2num_box = relation_constraint.CreateFunctionBox("Converters", "Vector to Number") # returns FBBox

relation_constraint.SetBoxPosition( v2num_box, 450, 200 )

num2v_box = relation_constraint.CreateFunctionBox("Converters", "Number to Vector") # returns FBBox

relation_constraint.SetBoxPosition( num2v_box, 800, 200 )

mutilpy_box = relation_constraint.CreateFunctionBox("Number", "Multiply (a x b)")

relation_constraint.SetBoxPosition( mutilpy_box, 600, 100 )

# Connect boxes------------------------------------------------------------------------------

src_box_Out = findAnimationNode( src_box.AnimationNodeOutGet(), "Lcl Rotation" )

v2num_box_In = findAnimationNode( v2num_box.AnimationNodeInGet(), "V" )

FBConnect( src_box_Out, v2num_box_In )# connect src_box (atrribute Lcl Rotation) to v2num_box_In ( attribute V)

v2num_box_Out = findAnimationNode( v2num_box.AnimationNodeOutGet(), "X" )

mutilpy_box_In = findAnimationNode( mutilpy_box.AnimationNodeInGet(), "a" )

FBConnect( v2num_box_Out, mutilpy_box_In )

mutilpy_box_Out = findAnimationNode( mutilpy_box.AnimationNodeOutGet(), "Result" )

num2v_box_In = findAnimationNode( num2v_box.AnimationNodeInGet(), "X" )

FBConnect( mutilpy_box_Out, num2v_box_In )

num2v_box_Out = findAnimationNode( num2v_box.AnimationNodeOutGet(), "Result" )

trgt_box_In = findAnimationNode( trgt_box.AnimationNodeInGet(), "Lcl Rotation" )

FBConnect( num2v_box_Out, trgt_box_In )

My problem is how to set the parameter for b [number] connection. This a float value used within the Multiply box. The following image shows this connection marked in red:

I’ve tried ProperyList within the “Multiply (a x b)” box but can’t find any Parameter that could be it.

mutilpy_box = relation_constraint.CreateFunctionBox("Number", "Multiply (a x b)") 
print(mutilpy_box.PropertyList.Find("Name"))

Any help would be great :slight_smile:

1 Like

I managed to solve it!

Here is the code:

#Create "Relation" Constraint 
constriant_name = "Twist_Jnt_ConRelation"
relation_constraint = FBConstraintRelation(constriant_name)
relation_constraint.Active = True # Turn constraint on!```

mutilpy_box = relation_constraint.CreateFunctionBox("Number", "Multiply (a x b)") 

twistoffset = -0.8
inplugs = findAnimationNode(mutilpy_box.AnimationNodeInGet(), "b") # Get "b" connection in node.
inplugs.WriteData([twistoffset]) # Offset
2 Likes