# give Python access to Blender's functionality import bpy # extend Python's math functionality import math
# add a cube into the scene bpy.ops.mesh.primitive_cube_add() # get a reference to the currently active object cube = bpy.context.active_object
# insert keyframe at frame one cube.keyframe_insert("rotation_euler", frame=1) # change the rotation of the cube around z-axis cube.rotation_euler.z = math.radians(360)
# insert keyframe at the last frame cube.keyframe_insert("rotation_euler", frame=90)
# change the location of the cube on the z-axis cube.location.z = 0 cube.keyframe_insert("location", frame=100) cube.location.z = 5 cube.keyframe_insert("location", frame=150)
# give Python access to Blender's functionality import bpy # extend Python's math functionality import math # extend Python functionality to generate random numbers import random
defanimate_rotation(obj, current_frame, rotation_frame_count): # remove the animation data from the duplicated object obj.animation_data_clear()
# add first cube mesh into the scene bpy.ops.mesh.primitive_cube_add(scale=(0.5, 2, 0.1)) obj = bpy.context.active_object obj.rotation_euler.z = math.radians(random.uniform(0, 360)) bpy.ops.object.transform_apply()
# create variables for stacking and rotating angle_step = 3 current_angle = 3
# create variables for animating the rotation current_frame = 1 frame_step = 1 rotation_frame_count = 90
# animate the original mesh animate_rotation(obj, current_frame, rotation_frame_count)
# stack and rotate the mesh while current_angle < 360: # duplicate the mesh bpy.ops.object.duplicate(linked=True)
# set location and rotation obj = bpy.context.active_object obj.location.z += obj.dimensions.z obj.rotation_euler.z = math.radians(current_angle)