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 )