MotionBuilder Python newbie

Hey guys, are there any references I can use to start making some python scripts in MB? Unfortunately I have to use motionbuilder 7.5.

Just to get a feel for it all, can someone give me an example script that would:

create a parent constraint
take two objects: ‘bleep’ and ‘boop’
make ‘bleep’ a parent and ‘boop’ the child?

Hey Leo,

I’m currently setting up a MoCap Pipeline myself and have to dig a bit into MotionBuilder-Scripting. Here’s what I use:

from the site

dowload this
http://images.autodesk.com/adsk/files/motionbuilder_python_scripting_help.zip

this is for 2009. If you use 2010, then download the 2010 reference from the same website :slight_smile:

also very useful for pipeline development:
http://chrisevans3d.com/tutorials/mbui.htm

Guess you should be able to find the parenting that you are looking for in the reference :slight_smile:

If you have any other questions, feel free to ask :slight_smile:

Matti.

edit: Sry, read too quickly over the 7.5 issue. Guess the API is pretty much the same?

http://stores.lulu.com/count_zer0 the python masterclass is a great start.

As for a parent constraint example, here’s a way to do it:

from pyfbsdk import FBConstraintManager, FBSystem, FBVector3d, FBModelTransformationMatrix

def createParentConstraint( pSrcModel, pDstModel, pMoveToSource=True, pActive=True, pLock=True, pWeight=100.0, pTX=True, pTY=True, pTZ=True, pRX=True, pRY=True, pRZ=True ):
    """
    creates of a parent constraint between source and destination model.

    FBModel pSrcModel
    FBModel pDstModel
    bool pActive - set the constraint active
    bool pLock - set the lock state
    bool pMoveToSource - if true copies translation and rotation values from source to destination, equivalent to
                            not snapping the constraint in the UI
    bool pTX, pTY, pTZ, pRX, pRY, pRZ - constrain the translation and rotation axes respectively (ie: Affect X, Y, or Z)
    """

    CM = FBConstraintManager()    

    if ( pSrcModel == None ) or ( pDstModel == None ):
        return

    c = None
    lProp = None
    lRot = FBVector3d()
    lPos = FBVector3d()
    
    # 4 is index in the constraint manager list for parent constraint
    c = CM.TypeCreateConstraint( 4 )
    if ( c ):
            
        c.Name = "%s->%s_Parent" %( pSrcModel.Name.replace(':','_'), pDstModel.Name.replace(':','_') )
        c.ReferenceAdd(0,pDstModel)
        c.ReferenceAdd(1,pSrcModel)

            
        # copy the transform from source to destination if specified
        if not pMoveToSource:
            pDstModel.GetVector ( lRot, FBModelTransformationMatrix.kModelRotation, True )
            pDstModel.GetVector ( lPos, FBModelTransformationMatrix.kModelTranslation, True )
            
        # set the active state
        c.Active = pActive
            
        if not pMoveToSource:
            pDstModel.SetVector ( lRot, FBModelTransformationMatrix.kModelRotation, True )
            pDstModel.SetVector ( lPos, FBModelTransformationMatrix.kModelTranslation, True )   
            
        FBSystem().Scene.Evaluate()
        
            
        # set lock attribute
        lProp = c.PropertyList.Find( 'Lock' )
        if lProp:
            lProp.Data = pLock
           
        # set weight attribute
        lProp = c.PropertyList.Find( 'Weight' )
        if lProp:
            FBSystem().Scene.Evaluate()
            lProp.Data = pWeight
    
        # set the affects properties
        if ( pTX == False):
            lProp = c.PropertyList.Find( 'AffectTranslationX' )
            if lProp:
                lProp.Data = 0
                
        if ( pTY == False):
            lProp = c.PropertyList.Find( 'AffectTranslationY' )
            if lProp:
                lProp.Data = 0
                
        if ( pTZ == False):
            lProp = c.PropertyList.Find( 'AffectTranslationZ' )
            if lProp:
                lProp.Data = 0  
                
        if ( pRX == False):
            lProp = c.PropertyList.Find( 'AffectRotationX' )
            if lProp:
                lProp.Data = 0
                
        if ( pRY == False):
            lProp = c.PropertyList.Find( 'AffectRotationY' )
            if lProp:
                lProp.Data = 0
                
        if ( pRZ == False):
            lProp = c.PropertyList.Find( 'AffectRotationZ' )
            if lProp:
                lProp.Data = 0
            
    del ( CM, lProp, lRot, lPos )
    
    return c

from pyfbsdk import FBFindModelByName
lSrc = FBFindModelByName('Bleep')
lDst = FBFindModelByName('Bloop')

createParentConstraint( lSrc, lDst, pMoveToSource=False )