コミュニティ
MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Using Python Scripting to set a Zero key on selected object

2件の返信2
解決済み
返信
メッセージ1/3
vdebaie
2591 件の閲覧回数, 2 件の返信

Using Python Scripting to set a Zero key on selected object

Hi! I'm a long-time lurker, first-time poster.

 

I am trying to create a script that will add a "Zero" key to my selected object.

 

I have about 10 days of MotionBuilder python experience and I am a bit stuck trying to figure out how to use  FBAnimationNode and 

FCurve within python.

 

The supplied examples and google searches are bringing me little help.

 

Thanks. 

タグ(2)
2件の返信2
メッセージ2/3
jps
Advocate
次のアカウントへの返信: vdebaie

There are several ways to approach the problem.

Setting a key with a value of 0 on the fCurve. This will work like using the Zero Key button in the Keys Controls:

 

from pyfbsdk import *

 

 

def setTRKeyToZero( yourObject, currentTime 😞

    yourObject.Translation.SetAnimated(True) # make sure translations are "animatable"

    yourObject.Translation.GetAnimationNode().Nodes[0].FCurve.KeyAdd(currentTime,0)  #Node[0] is X, [1][ is Y, [2] is Z

    yourObject.Translation.GetAnimationNode().Nodes[1].FCurve.KeyAdd(currentTime,0) #  the last 0 is the key value

    yourObject.Translation.GetAnimationNode().Nodes[2].FCurve.KeyAdd(currentTime,0)

    yourObject.Rotation.SetAnimated(True)

    yourObject.Rotation.GetAnimationNode().Nodes[0].FCurve.KeyAdd(currentTime,0)

    yourObject.Rotation.GetAnimationNode().Nodes[1].FCurve.KeyAdd(currentTime,0)

    yourObject.Rotation.GetAnimationNode().Nodes[2].FCurve.KeyAdd(currentTime,0)

 

 

lPlayer = FBPlayerControl()

currentTime = lPlayer.GetEditCurrentTime()

selectedModelList = FBModelList()

FBGetSelectedModels( selectedModelList )

for selectedModel in selectedModelList:

    setTRKeyToZero( selectedModel, currentTime )

 

 

On other way will be to directly move the object and create a key using the transport control:

from pyfbsdk import *

 

def zeroTRTransforms( yourObject 😞

    yourVector = FBVector3d( 0, 0, 0 )

    yourObject.SetVector (yourVector, FBModelTransformationType.kModelTranslation, False) # False for local transform, True(default) for global transform.

    yourObject.SetVector (yourVector, FBModelTransformationType.kModelRotation, False)

 

 

lPlayer = FBPlayerControl()

selectedModelList = FBModelList()

FBGetSelectedModels( selectedModelList )

for selectedModel in selectedModelList:

    zeroTRTransforms( selectedModel )

    lPlayer.Key()

 

 

A symplified version were it's always a local tarnsform.

 

from pyfbsdk import *

 

def zeroTRTransforms( yourObject 😞

 

    yourObject.Translation = FBVector3d()

    yourObject.Rotation = FBVector3d()

 

lPlayer = FBPlayerControl()

selectedModelList = FBModelList()

FBGetSelectedModels( selectedModelList )

for selectedModel in selectedModelList:

    zeroTRTransforms( selectedModel )

    lPlayer.Key()

 

 

Sometimes you will need to use FBSystem().Scene.Evaluate() after changing the transforms of an object to make sure current transforms values are updated.

メッセージ3/3
vdebaie
次のアカウントへの返信: vdebaie

Thanks jps. I will give this a try. 🙂

お探しの情報が見つからないときは、コミュニティで質問しましょう。困っている人がいたら、情報を教えてあげましょう。

フォーラムに投稿  

Autodesk Design & Make Report