Animation with Python

Hey,

I wanted to know if it is possible to animate pictures via python and blender. Like, when I want to animate a .blend, so that it will turn 10 times round 5° . Is it possible to do that?

Heres a pseudocode:

import Blender

obj = Blender.selectedOject()

for i in xrange(10):
    obj.turn(5)
    Blender.animation.takeNewShot()
    
Blender.saveAs("fileAsAnimation.blend")

Is something like this possible? And if yes, where can I find out how to do this?

Thank you,

INFACT

The general answer to such kind of questions is always ‘YES’! :spin:

Now the questions transforms into two new ones - “Why do so?” and “How to do it?”… I wont answer to the first one cause it is much simpler to do THIS by appropriate IPO curves or an armature. The answer to the second question, in the light of you pseudo code may look like this (code for Blender 2.4x):

from Blender import *
import bpy

def Dynamic_anim_test():
    sce = bpy.data.scenes.active
    ob = sce.objects.active
    x,y,z = ob.loc
    n = 10
    context = sce.getRenderingContext()
#    context.sizePreset(Scene.Render.PC)
    context.imageType = Scene.Render.JPEG
    renderPath = context.getRenderPath()
    Scene.Render.EnableDispWin()
    for i in range(n):
        x += 0.5
        ob.loc = x,y,z
        context.render()
        filename = renderPath+"IMG_"+str(1000+i)+".jpg"
        context.saveRenderedImage(filename)
    Scene.Render.CloseRenderWindow()
    return

#######################################################

Dynamic_anim_test()


This show an implementation of translation of the object. Rotation is implemented using the same principle :wink:

Now my question to OTHERS is: Why having the “context.sizePreset(Scene.Render.PC)” isolated from the active code as above results in proper “normal” (as of rendering via the ANIM panel) rendering while in case that command is active the result is just a blinking rendering???

To extend the issue raised in this thread, I will open another thread dealing with animating only part of the object which I think is more reasonable and which I am very much interested these days.

Regards,

EDIT: My promised thread is here

Wow, nice! Now I can move objects.
How can I add it to a frame, when I want to make an animation out of it?

Edit: Or where can I find it out?

What do you mean “How can I add it to a frame”?

Sorry, my English is not perfect… pls explain.

Im not a blender pro, but an animation is made out of frames. Like a video. A video are many pictures ( = frames) played in a row. Or like a Flipbook, its made out of a lot of pictures. When Im right, you make a cube, press something like “Add to anim” or so, move the cube and click “Add to anim” again, until you have enough frames.

My english isnt perfect either. sorry

Ughhh, yes, ok… I know about the frames that compose the clips, video, etc. Perhaps your question now is similar to the one I posted in my other thread related to this one here… You can check it here… But I dont have the answer NOW TO do that, eh :wink:

Regards,

Dont you ask for saving it as an video?
I want to save it as an animated blend.

I am not sure if ‘animated blend’ exists… At least I havent worked with such format… My question in the other thread refers to manipulating the mesh at selected places between rendering adjacent frames in VIDEO output mode, yes! :wink:
If you simply change the output format in the codes published in this and in the other thread, you will get the whole video rendered n-times, which - obviously - is NOT the effect I am looking for :eek:

Regards,

Im talking about programming something like this: http://www.youtube.com/watch?v=FAZFfLmbD2k
So I musnt do it by my self.

Doesnt that work? In the video you can see how to do it by hand. But I want to do something similar with a python program. I saw this walk.o.matic but I didnt test it. Doesnt it make a character or something like that “walk”? That would be something I am looking for, but just not for walking, but for moving an object

the walk-o-matic is a python-script for blender-2.49
and uses as an object:
some emptys.
An empty is the simplest object in blender, its just a point (not from a mesh) with an orientation.
walk-o-matic animates an empty for the left and right foot and for the base.
If you want to do something similiar for blender-2.5, you have to do some programing, and to update such kind of scripts for blender-2.5.
There are still some things, which will not work,
one first point could be to visit the bvh-import-script.
Take a bvh-file (a file with animation-data) and import it, it creates an armature and does the animation according to the bvh-file values.
Instead of doing the complex job of an armature-animation in pose-mode,
the animation of an empty is easy - (but beware, its not trivial).
Check this python&plugins forum-part for examples about blender-2.5 scripting, and! check the included scripts (they are inside your local directory in the blender path: .blender/scripts/…)

Im still using 2.49 and I want to save an animation in a blend or .x file.
But I dont know how to animate the object. Where can I get this info?

Hi,

Why are you using Python for this?

Do you know the normal way of animating an object? Select the object, move it to the position you want, press I, select the kind of key you want to insert (e.g. Loc sets a location keyframe), move to another frame (right arrow key), move the object, press I to insert another key. Press ALT-A to play back your animation. Press Anim in the render buttons to render the animation.

(Please ignore if you know all this already. I’m just making sure you’re not making things unnecessarily difficult for yourself.)

I dont want to do it by hand, because there are to many objects it want to animate. They are all a bit different, but they should be animated the same way

Hi,

If they should all be animated the same way, you could link them all to the same IPO and make sure the IPO only contains DLoc, DRot and DScale curves so all the objects move relative to their starting positions.