Created
January 4, 2023 21:16
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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