animation script tutorial

hey there…

does any have or know of any good (basic) animation script tutorials/examples??? (for a sphere to be even more specific)


I’m going to have to second ro’s request…does anyone know??

I’d greatly appreciate it…thanks in advance.

Not sure from your question what it is you want but you can start here:

and if that’s not it look at the rest of jms’ python stuff starting here:


What I need…and what I think ro needs is just an example of a python script for a simple animation of a sphere, moving from point A to point B. Then I’ll pluck what I can from that, and then write a more fitting script. I just need a basic idea of what is needed.

This is as simple as it gets :wink: Hope it helps:
anim Python file


Thanks nozzy…

I’m not that…ok, not well scripted at all in python…so bear with me…

First of all, what’s a float??



Does the the 0, frame, 0 part mean x, y, z, respectively??


A variable type. There are many differant types:
A few, “Interger” a whole number 1,2,3. A “String” a letter, word or sentence, and our “Float” a decimal , eg, 1.556.

The “Curframe” is converted to a float because it returns a string, and
to a float to make the animation run smoother smaller steps, if I used a interger it would hack more.

Thats right, “frame” is the variable holding the current amount the sphere is going to be moved.

No probs, hope it makes things a little clearer.


Also… don’t go chasing the Python just because it’s the first approach to the problem which came to mind! You can easily accomplish the animation of a sphere by use of keyframes, actions and so-on without writing one drachma of procedural code.

thanks sliver and nozzy!!

sundialsvc4: i think i need to script it considering i need to put in a few thousand spheres for my thing. doing it normally will be way too hectic. :smiley:

speaking of which, now that i have this script for my sphere:

import Blender
from Blender import NMesh

import math
from math import * 




print n

radius = 2.0

for i in range(0,n):
	print i
	for j in range(0,n):
		print j

print n0

for i in range(0, n-1):
	for j in range(0, n-1):

NMesh.PutRaw(me,"sphere", 1)

how do i loop it so that i get more than one sphere for each frame?? i’m going to need a few thousand moving around, each with different radii , so what and where do i do it?? i am so clueless… :expressionless:

I truly have difficulty imagining any image that has “literally thousands” of spheres in it. But perhaps.

Your script will presumably need to loop through all of the objects and calculate their new positions one-by-one.

I suggest that you look carefully to see if there is not some way to simplify the problem. For example, can the viewer really perceive a difference between 100 frenetic spheres and 1,000? Can the desired effect be achieved by 10 layers each containing 100 spheres, sandwiched one on top of the other and maybe offset by a few frames?

Maybe you can check this site out, with the basics in python :slight_smile:
learning to program


sundialsvc4: well, i kind of actually need all those spheres b/c i already have a designated number of spheres/molecules, each w/ different x,y,z coordinates, changing everytime they move. all these molecules are someway connected to each other, directly or indirectly, so i need all thousands of them. if i leave some out, the molecule interaction becomes inaccurate, or well, simply wrong.

nozzy: thanks!! i’ll see what i can wrap around my computer illiterate brain :-?

Hey, it sounds like you are doing something similar to a project I was working on a few months ago. We were running polymer simulations and needed a good visualization program.

Your script just makes a sphere, yea?

Theeth suggested just putting a sphere (or other object) in another layer, then just getting the mesh from that. It makes things MUCH simpler when you need more complex objects like cylinders for bonds and such.

Basically this is all you need:

for i in range( 0, blah):

    beadMesh = NMesh.GetRaw( "Sphere" )
    beadMesh.addMaterial( someMaterial )

    tempSph = NMesh.PutRaw( beadMesh, "MyName" + `i`, 1)
    tempSph.setLocation( someX, someY, someZ )
#end i

the “Sphere” above is the name of a sphere object that is hidden on say layer 3, and put in only once just before you run the script. I just saved it as a .blend file, and ran the script with different coordinate files.

the tempSph handle is important because then you can do things like add materials, which you set up in advance, or can be set up with code, depending on how you do it. The “MyName” + i part is extremely important because each object must be named differently, or it will just over write the old one.

I hope that helps, it is kind of the product of months of head banging and lots of help from this forum. (If you do a post search for Squirrel, you can see most of this. There also might be some interesting tid bits for you there too.)

Good luck, and let me know if this helps!

Hope he is still watching this post…

Do not forget to give the original addresses of this script:

squirrel: thanks!! i’ll see what i can wrap my head around :-?

jms: sorry bout that :expressionless: …but thanks for the guidance!! :smiley: