PDA

View Full Version : Index of keyframes using Python


LoneCanuck
05-10-2007, 11:42 AM
Anyone know a way of returning a list of keys on a selected object through Python?

Neill
05-11-2007, 10:02 AM
Anyone know a way of returning a list of keys on a selected object through Python?

I know :), each model (class FBModel) has several animation nodes like translation, rotation, scale & visibility. All this nodes that I have counted are in the nodes attribute of the animationNode property in FBModel class. To detect animationNode use Name property, that can give U information of node usage. continue... in animation node class (FBAnimationNode) u can find attribute KeyCount and FCurve (class FBFCurve) which own all keys for this animation node.

P.S. use MB help to Python, what is very usefull

LoneCanuck
05-14-2007, 10:42 AM
Hi Neill,

Thanks for the reply. I've gone through the documentation and it's still not clear how to get the results I am looking for. For the animation nodes, I have used the following code to try to get the names of the anim. nodes underneath the object "Cube".

-------------------------------------------------------
from pyfbsdk import *
lObject = FBFindModelByName("Cube", None)
lObject.Selected = True

lNodes = lObject.AnimationNode.Nodes

for nodes in lNodes:
print lNodes
-------------------------------------------------------

It works, except that I get the code object name and not the "literal" name (ie: LclTranslation, etc...). I tried using the .name call but it doesn't work in the this case.

Ultimately, I need to get to the FCurve level of the object, but my understanding on how MB Python works is that, first, I need to select the object, get the animation node (by name), get to the fcurve, THEN get the index of keys that I want to do my magic on.

Please let me know if this is correct and how I may pull the literal string of the animation node names from the list.

/LoCK/

LoneCanuck
05-14-2007, 10:51 AM
Actually, I figured out the naming thing.

-------------
from pyfbsdk import *
lObject = FBFindModelByName("Cube", None)
lObject.Selected = True

lNodes = lObject.AnimationNode.Nodes

for nodes in lNodes:
print nodes.Name
-------------
This give me the names...

Neill
05-14-2007, 10:51 AM
To obtain name of the AnimationNode use .UserName property like this

lNodes = lObject.AnimationNode.Nodes
if lNodes:
for node in lNodes:
print node.UserName

Your workflow depend on tast. So if U want to get some keys, U need to get object animation node where nodes are translation, rotation, scale and so on. Then, for example in translation there are X,Y,Z nodes, which have FCurve with keyframes.

LoneCanuck
05-14-2007, 07:43 PM
Hey Neill,

Yeah, I used .Name and it prints them out nicely. Never tried .userName though.

Maybe you can answer this code type question, while we are on the subject.

The code docs list something like this.

SwitchViewerCamera (FBCamera pCamera)

Now, SwitchViewerCamera is a part of the FBApplication function, so I declare it by stating:

lApp = FBApplication

Now, since it's calling FBCamera, how does the syntax work when a function calls another function, as part of it's call?

I tried using lApp.SwitcherViewerCamera ('Camera') but that doesn't do a thing...

I tried declaring FBCamera as lCam = FBCamera ('Camera')

and the code runs, but doesn't do what want.

Frustrating without any sort of script feedback inside MotionBuilder.

Cheers,

LoneCanuck

Neill
05-15-2007, 08:29 AM
Hi LoneCanuck,

there is a mistake in your code. To switch between cameras in viewer using application class, U need evalute code like this:

camModel = FBModel()
camModel = FBFindModelByName( 'MyCamera' )

# here 'MyCamera' is a camera name and camModel is a camera model

# now let's switch to MyCamera
FBApplication().SwitchViewerCamera( camModel )

That's all

LoneCanuck
05-15-2007, 09:25 AM
Hi Neill,

It had a problem with declaring the "camModel = FBModel()" but removing that made it work!

So my problem was how I was calling the SwitchViewerCamera call.


How do you know when to leave in the ellipses for a function and not? Some functions need to be called function.attribute, as opposed to function().attribute, etc...?


Thanks a ton for clearing this up.

LoneCanuck

PS - You should DEFINITELY be posting on the Autodesk Python forum. We could all definitely use the help.

Neill
05-15-2007, 10:31 AM
In MB Python there are a list of classes that are individial like FBApplication. In help system U can find hints about this. And it's situation when U use class().function/attribute call.

> PS - You should DEFINITELY be posting on the Autodesk Python forum. We could all definitely use the help.
Ok, I will visit this forum...
To tell the truth, I have tried to connect to MB developing team, cause I have a lot of interesting ideas and usefull ready scripts/plugins for this product to make it better. but... they don't reply at all :sad:

LoneCanuck
05-15-2007, 07:22 PM
Not surprising. Ever since they were bought by Autodesk, the support people, unless you are on Platinum Contract, have been pretty absent. And quiet.

/LoCK/

CGTalk Moderation
05-15-2007, 07:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.