Samples/Character/CharacterMarkerSet.py

# Copyright 2012 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Shows how to create Character Marker Set and setup markers
#
# Topic: FBCharacter
#
from pyfbsdk import *
import random 

def CreateAndSetupMarkerSet(pCharacter):
    # Create marker set
    pCharacter.CreateCharacterMarkerSet(True)
    
    # Get newly created marker set
    lMarkerSet = pCharacter.PropertyList.Find("MarkerSet")[0]
    
    # Get property list for hips markers
    lHipMarkers = lMarkerSet.PropertyList.Find("Hips.Markers")
        
    # Create markers - just to be able to show how to assign them to joint
    lJointModel = pCharacter.GetModel(FBBodyNodeId.kFBHipsNodeId)
    lMarkerModel_T = FBVector3d()
    
    if lJointModel:
        for i in range(4):
            lJointModel.GetVector(lMarkerModel_T, FBModelTransformationType.kModelTranslation, True)
            lMarkerModel_T[0] = lMarkerModel_T[0]+random.randint(-30, 30)
            lMarkerModel_T[2] = lMarkerModel_T[2]+random.randint(-30, 30)
            lMarker = FBModelNull("Marker")
            lMarker.SetVector(lMarkerModel_T, FBModelTransformationType.kModelTranslation, True)
            lMarker.Show = True
            
            if lMarker:
                lHipMarkers.ConnectSrc(lMarker)
                
        lNewGoalModel = pCharacter.GetGoalModel(FBBodyNodeId.kFBHipsNodeId)
        
        if lNewGoalModel:
            lVec = FBVector3d()
            lVec2 = FBVector3d()
            
            # check snap position
            lNewGoalModel.GetVector(lVec, FBModelTransformationType.kModelTranslation, True)
            lJointModel.GetVector(lVec2, FBModelTransformationType.kModelTranslation, True)
        
            print lVec, lVec2
        
            # check snap rotation
            lNewGoalModel.GetVector(lVec, FBModelTransformationType.kModelRotation, True)
            lJointModel.GetVector(lVec2, FBModelTransformationType.kModelRotation, True)
        
            print lVec, lVec2
            
        # Unassign the last added marker.
        if lMarker:
            lHipMarkers.DisconnectSrc( lMarker )
            
            
lCharacter = FBApplication().CurrentCharacter
if lCharacter:
    CreateAndSetupMarkerSet(lCharacter)