Skip to content

Instantly share code, notes, and snippets.

@CGArtPython
Created January 4, 2023 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CGArtPython/11927dffa39a378fa00f7ab514e76f07 to your computer and use it in GitHub Desktop.
Save CGArtPython/11927dffa39a378fa00f7ab514e76f07 to your computer and use it in GitHub Desktop.
Final code for a Beginner Blender Python Exercise: Easy cube rotation animation (link to tutorial: https://www.youtube.com/watch?v=tBPuEWh88Lo)
# 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
start_frame = 1
cube.keyframe_insert("rotation_euler", frame=start_frame)
# change the rotation of the cube around z-axis
degrees = 360
radians = math.radians(degrees)
cube.rotation_euler.z = radians
# insert keyframe at the last frame
end_frame = 180
cube.keyframe_insert("rotation_euler", frame=end_frame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment