animation using python scripting

:smiley: :smiley:
We are actually working on a project which deals with python scripting in Blender.We have to create a sphere in Blender using Python scripting and then animate the sphere.Animating here means we have to actually move the sphere from one location to another.

 We have created the sphereusing python scripting  but we are stuck in the animation part which is also to be done in python scripting..
  
Any suggestions are welcome. Please send a reply. [/i]

Moving stuff around with Python is (IMO) easier than creating whole mesh objects.

You make a Python object out of your mesh object like this:

obToMove = Blender.Object.Get(‘YourSphere’)

Assuming of course that the name of your created sphere is “YourSphere”

Then, you set the location of the object like this:

obToMove.setLocation(15,-4.2,7)

Then do a:

Blender.Redraw

This is how you set locations. If you want to actually have Python generate animation you can play back later, you need to record this in IPOs, which is a little more involved. Also, the IPO module is broken right now, so you can’t generate smooth IPO animation from within Python. I’ve made a fix for it, but it hasn’t entered the cvs yet.

Here’s code for making an IPO for the x-value of the object. You can dupe it for y and z as you see fit:


obToMove.clearIPO() #deletes any IPOs currently attached to the object
obIPO = Blender.Ipo.New('Object','obIPO') #creates a new, unlinked IPO object
obToMove.setIpo(obIPO) #links the new IPO to your object
obIPOX = obIPO.addCurve('LocX') #adds a curve for x-value
obIPOX.addBezier((3,15)) #set a key at frame 3, x-value 15
opIPOX.addBezier((5,10)) #set a key at frame 5, x-value 10
obIPOX.addBezier((10,0)) #set a key at frame 10, x-value 0, etc.

obIPOX.setInterpolation('Bezier') #set to smooth IPOs
obIPOX.Recalc #fix bezier handles

I know that seems like a lot to do, but you also need to make curves for the Y and Z values as well! Of course, once you have the curves made, you can just keep adding keys to them. If your script is making new keys procedurally, you only need to initialize and create the curves once.

Good luck.

Edit: added the double parans in the addBezier method.

:smiley: :smiley:
Hello we tried your code.But there is no change in the program . The sphere does not move

at all.

with the help of our code we create a sphere that is first the vertices and then the faces.

The code given by you that is
obToMove.setLocation(15,-4.2,7)

does not show us the animation. It is because the sphere will be drawn with the vertices and then the faces.
And after writing the code given by you it may move but the sphere has to be redrawn wirth the faces and the vertices. .So how do we do that.

Hope you understood our problem.