MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

my parent constraint tool

3 REPLIES 3
Reply
Message 1 of 4
xatmo
935 Views, 3 Replies

my parent constraint tool

Hello everyone,

 

I started a blog where I hope to periodically post new tools, tips etc.

The 1st useful thing I've posted is a simple parent constraint tool:

 

http://www.sternativo.com/?p=146

 

any feedback, let me know 🙂

 

thanks!

--------------------------
www.sternativo.com
3 REPLIES 3
Message 2 of 4
xatmo
in reply to: xatmo

hey I've updated the script.

Now is more efficient and it will change the name in the navigator based on the type of constraint (I've set it to work only on position, rotation and parent but it's easy to modify it) so it will look like this:

 

Capture.PNG

 

def constraint(CONSTRAINT_TYPE = 3, Weight = 100, SNAP = True, child = None , parent = None  ):
    #assign child and parents variables and check if the right amount of items are selected
    if child == None or parent == None:
        selectedModels = FBModelList()
        FBGetSelectedModels (selectedModels, None, True, True)
        if len(selectedModels) <= 1 or len(selectedModels)> 2 :
           FBMessageBox( "Error", "Please select two items", "OK" )
           return
    
    selected_objects = [FBFindObjectByFullName(model.FullName) for model in selectedModels]
    child = selected_objects[0]
    parent = selected_objects[1]
    
    '''
    CONSTRAINT_TYPE_AIM = 0
    CONSTRAINT_TYPE_EXPRESSION = 1
    CONSTRAINT_TYPE_MULTI_REFERENTIAL = 2
    CONSTRAINT_TYPE_PARENT_CHILD = 3
    CONSTRAINT_TYPE_PATH = 4
    CONSTRAINT_TYPE_POSITION = 5
    CONSTRAINT_TYPE_RANGE = 6
    CONSTRAINT_TYPE_RELATION = 7
    CONSTRAINT_TYPE_RIGID_BODY = 8
    CONSTRAINT_TYPE_3_POINTS = 9
    CONSTRAINT_TYPE_ROTATION = 10
    CONSTRAINT_TYPE_SCALE = 11
    CONSTRAINT_TYPE_MAPPING = 12
    CONSTRAINT_TYPE_CHAIN_IK = 13
    '''
    #setting te prefix for the name displayed on the constraint based on its type
    if CONSTRAINT_TYPE == 3 : constraint_name = "par_"
    elif CONSTRAINT_TYPE == 5 : constraint_name = "pnt_"
    elif CONSTRAINT_TYPE == 10 : constraint_name = "rot_"
    else: constraint_name = ""
    
    #constraint creation with type and name
    myManager = FBConstraintManager()
    myCons = myManager.TypeCreateConstraint(CONSTRAINT_TYPE)
    myCons.Name = constraint_name + child.Name + "_to_" + parent.Name
    
    #adding elements to the constraint slots
    #for index, element in enumerate(selected_objects):
    myCons.ReferenceAdd (0, child) #if I add an index > 1, it wont be added to the slot(dont know why)
    myCons.ReferenceAdd (1, parent) #if I add an index > 1, it wont be added to the slot(dont know why)
    
    #setting up the snap option, so the elements will keep their position
    if SNAP == True:  
      myCons.Snap()
    #weight of the constraint
    myCons.Weight = 100
    myCons.Active = True

constraint(CONSTRAINT_TYPE = 3, Weight = 100, SNAP = True, child = None , parent = None  )

 

hope it helps 🙂

--------------------------
www.sternativo.com
Message 3 of 4
madcarrot2007
in reply to: xatmo

Hi xatmo, well written!
Instead of putting number as argument to specify type of constraint, i would use the name of the constraint instead. Because you would forget which number is for generating which constraint very soon and you wouldn't want to read your script everytime you use the function.
i.e constraint(CONSTRAINT_TYPE = 'Point', Weight = 100, SNAP = True, child = None , parent = None )

my 2 cent.
Message 4 of 4
xatmo
in reply to: madcarrot2007

yes good point. Somebody else addressed this feedback and I've fixed it already but I didn't update it online 😛

thanks!
--------------------------
www.sternativo.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report