Feb 202011
 

[EDIT] – Just wanted to post this here in case I forget:

A driver can use the current frame in the expression with – bpy.context.scene.frame_current

So you could do something like: sin((bpy.context.scene.frame_current-10)/5)

BUT!!! After 2.68 expressions in drivers only work if you have Auto Run Python Scripts turned on in UserPrefs>File

————————————

B2.56 doesn’t have proper events yet – so this is a hacky way to drive scene animation. I forgot where I found this info – but it worked so I wanted to make it available.
1) create Empty
2) add single keyframe to Zrot (frame 1)
– should have default expanded poly generator on it
3) add single driver to Yloc (frame1)
– in Drivers> choose – Scripted sxpression
– enter this expression

float(exec("\n".join([l.body for l in bpy.data.texts["RUN"].lines]))==None)

4) then a script called ‘RUN’ should execute every time the frame changes
– Zrot of Empty drives expression which (i think) grabs the text datablock of the script and runs it

here’s a quick thing I did. set up the empty as above…
then make a cube (named ‘Cube’) subdivide it a lot, then run this-

 import bpy import random ob = bpy.data.objects['Cube'] verts = ob.data.vertices for v in verts: rxnum = round(random.uniform(-0.01 ,0.01), 4) rynum = round(random.uniform(-0.01 ,0.01), 4) rznum = round(random.uniform(-0.01 ,0.01), 4) v.co[0] = v.co[0] + rxnum v.co[1] = v.co[1] + rynum v.co[2] = v.co[2] + rznum scene = bpy.context.scene 

BLENDER ARTIST THREAD

  2 Responses to “Blender – Python Driven Animation”

  1. […] won’t bother to post the code because the framechange event stuff is still a nightmare and the actual ruleset code is too easy. Recommend on Facebook Share on […]

  2. […] Also – the script runs on each frame change. Here’s how that works (WARNING: kinda hacky) http://funkboxing.com/wordpress/?p=236 […]

Leave a Reply