PDA

View Full Version : Maya Animations using Python


Yick
12-06-2011, 07:00 AM
Hey, I am new to Maya. I am trying to do a simple animation using Python. I have a surface that I would like to pivot +45 degrees on the y-axis after 5 frames, -45 degrees over the next 5, -45 degrees again after the next 5 and then +45 degrees after the last 5 (20 frames total). I would also like to ensure that this occurs infinitely.

Like I said, I`m new, so if you need more info let me know.

Thanks!

uiron
12-06-2011, 07:07 AM
this could be simply done by looping animation curve, no coding needed.

what's the context of this, why do you want python? are you new to maya, python, or both? smells like a homework assignment:]

HOW do you want to do that in python? generate a bunch of keys over given timeframe range? setup animation curves via python? write a custom node that will supply rotation values? by the way, the last option is the only one i can think of that satisfies all your criteria (python AND occur infinitely), but would be a major overkill for such task.

Yick
12-06-2011, 07:19 AM
Definitely a homework assignment. We (unfortunately) must do all of the animation work procedurally. I would look into MEL, but there's a surprising lack of documentation available, plus I'm already familiar with Python. I suppose it doesn't have to loop infinitely. How would YOU do it? And we'll start there. :P

uiron
12-06-2011, 07:29 AM
since it's a homework assignment...:]

keyframing part will be easy, just have a look at examples in setKeyframe() documentation.

as for the looping part... well, you can just generate a bunch of keys, this just means repeting the same thing you did on frame 0 on frames 0+n, 0+2*n, etc;
you can be smarter and use maya's animation looping utilities, but from script that will require selecting all animation curves of the object

animCurves = cmds.listConnections(yourObject, source=True, type="animCurve")


...and doing setAttr() on "preInfinity" and "postInfinity" attributes of each anim curve (with value "3", for Cycle behaviour, have a look at nodes->animCurve documentation)

Yick
12-06-2011, 07:33 AM
Thanks for the reply, I'll look into that.

Random question, I don't suppose it's possible to derive the MEL or Python script from an animation? I already managed to create the animation I want just using the tools in Maya without any coding, and it would kick ass if I could somehow just extract the code from it :P Not that I'm expecting it's possible...

uiron
12-06-2011, 07:46 AM
while you're working, you can see pretty much everything you're doing in script editor (window-general editors - script editor). if you turn on "history - show all commands", it's even more detailed, though you get UI update calls and stuff, which clutters log pretty badly.

CGTalk Moderation
12-06-2011, 07:46 AM
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.