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: 

setting keys on specified objects

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
1335 Views, 4 Replies

setting keys on specified objects

Hi !

Could anyone help me on how to set keys on multiple specified object(ex.: locator*) if there is no keys yet.
I tried with some example from ther forum but i'm not a programmer so i got stuck.Here is my try :

 
from pyfbsdk import *

lScene = FBSystem().Scene

iValue = 10 # sample value
iFrame = 10 # sample value

def FindAnimationNode( lScene, pNode ):
print("test first")
lResult = None
lName = pName.split( '/' )
for lNode in pNode.Nodes:
print("test second")
if lNode.Name == lName:
if len( lName ) > 1:
print("exist")
lResult = FindAnimationNode( pName.replace( '%s/' % lName, '' ), lNode )
else:
print("not exist")
lResult = lNode
break;
return lResult


def KeyAnimation( pName, pDst ):
print("test third")
lAnimNode = FindAnimationNode( pName, pDst.AnimationNode )
print("test fourth")
if lAnimNode.FCurve:
for lKey in lAnimNode.FCurve.Keys:
lAnimNode.KeyAdd( 10, 10 )


for lcon in lScene.Components:
if lcon:
# searching for constraint with locator in name
if lcon.Name.find("locator") != -1:
lDst = lcon.Name
print (lcon.Name)
KeyAnimation( 'Lcl Translation/X', lDst )




there is an error message : 'str' object has no attribute 'AnimationNode` (in line 28:lAnimNode = FindAnimationNode( pName, pDst.AnimationNode ))

thanks in advance

Ashraf
4 REPLIES 4
Message 2 of 5
_KxL_
in reply to: Anonymous

Can you describe what you want to do? Where you want to set key, and for what kind of objects?

Here is a quick script for placing an key ( x15,y10,z50 ) on selected models translation curve. To test: add cube to scene, select it, and run script:


from pyfbsdk import FBModelList, FBGetSelectedModels, FBPropertyManager, FBVector3d

def SetKey( pAnimationNode, pValue):
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)

lModelList = FBModelList()

# Get the selected models.
FBGetSelectedModels( lModelList )
for lModel in lModelList:
SetKey(lModel.Translation.GetAnimationNode(), FBVector3d(15,10,50))

# Cleanup.
del( lModelList, SetKey )
del(FBModelList, FBGetSelectedModels,FBPropertyManager, FBVector3d)

Message 3 of 5
Anonymous
in reply to: Anonymous

Hi !

First of all thank You very much for Your help.
I tried to set keys on Nulls on translate X,Y,Z all the null has a prefix "locator" +counter.My main purpose is to key all nulls named "locator" without selecting them.
I tried to implement Your Code ,but whwn it comes to the for loop it stops with an error:iteration over non sequence.Maybe FBGetSelectedModels does not returns an array?
Thank You again

Ashraf



from pyfbsdk import FBModelList, FBGetSelectedModels, FBPropertyManager, FBVector3d,FBModelTransformationMatrix,FBSystem,FBFindModelByName,FBModel


lModelList = FBSystem().Scene


def SetKey( pAnimationNode, pValue):
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)

lModelList = FBFindModelByName("locator" , None)
if lModelList == None:
print("None Found")

for lModel in lModelList:
lModel.Selected = True
tvector = FBVector3d()
lModel.GetVector(tvector, FBModelTransformationMatrix.kModelTranslation)
SetKey(lModel.Translation.GetAnimationNode(), tvector)

# Cleanup.
del( lModelList, SetKey )
del(FBModelList, FBGetSelectedModels,FBPropertyManager, FBVector3d, FBModelTransformationMatrix,FBSystem,FBFindModelByName,FBModel)

Message 4 of 5
_KxL_
in reply to: Anonymous

Sorry, but I am not sure if you know what you are doing. Function:

FBFindModelByName(...)


finds a model, not an list of models. So why you want to iterate it?


Evaluate this script. It should be close to what you are looking for:

from pyfbsdk import FBSystem, FBScene, FBVector3d

def SetKey( pAnimationNode, pValue):
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)
pAnimationNode.Nodes.KeyAdd(pValue)

def LookInHierarchy(pRoot, pPrefix):
if pRoot:
if pRoot.Name.find(pPrefix)==0 :
SetKey(pRoot.Translation.GetAnimationNode(), FBVector3d(15,10,50))

for lChild in pRoot.Children:
LookInHierarchy(lChild, pPrefix)


LookInHierarchy(FBSystem().Scene.RootModel, 'locator')

# Cleanup.
del( LookInHierarchy, SetKey)
del( FBSystem, FBScene, FBVector3d )


SetKey does what it says. LookInHierarchy goes through scene models and looks for ones that name starts from 'locator'. When it finds it key is being set.
I do not know if you want to add key with given value or insert at given time. Check in FBAnimationNode and FBFCurve if you want some other key functions.
Message 5 of 5
Anonymous
in reply to: Anonymous

Thank You very much for the reply, this helped me a lot this was exactly i was looking for. Previously i thought FBFindModelByName returns a list so i was confused, now it's clear so thank You again!

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

Post to forums  

Autodesk Design & Make Report