Skip to content

Instantly share code, notes, and snippets.

@davidair
Created February 25, 2024 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidair/ba4afe8a8d11a6c314845854ade465f6 to your computer and use it in GitHub Desktop.
Save davidair/ba4afe8a8d11a6c314845854ade465f6 to your computer and use it in GitHub Desktop.
Blender Script to continuously animate cubes of different heights
import bpy
import random
def my_animator(scene):
print("Frame change", scene.frame_current)
if scene.frame_current == 100:
bpy.ops.object.delete()
bpy.ops.mesh.primitive_cube_add(scale = (1, 1, 1 + random.uniform(0, 2.0)))
cube = bpy.context.active_object
cube.location.x = 10
cube.keyframe_insert("location", frame=1)
cube.location.x = -10
cube.keyframe_insert("location", frame=100)
bpy.app.handlers.frame_change_pre.clear()
bpy.app.handlers.frame_change_pre.append(my_animator)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment