Created
June 1, 2023 03:19
-
-
Save CGArtPython/83a324c9938216c91df746c15179e992 to your computer and use it in GitHub Desktop.
Beginner Blender Python tutorial code for a cube location animation (link to video: https://www.youtube.com/watch?v=nmJqIaSZlRs&lc=Ugw4q26HfFYOa0zv1Wh4AaABAg)
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 | |
# 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("location", frame=start_frame) | |
# change the location of the cube on the z-axis | |
cube.location.z = 5 | |
# insert keyframe at the last frame | |
end_frame = 180 | |
cube.keyframe_insert("location", frame=end_frame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was helpful. I'm going to refactor this to remove the hard-coded font object name, but here's an example in which I move the z position of some words from z = 0.4 to z = 0.54 across 50 frames:
def move_letter_behind():
font_object = bpy.data.objects["Font Object.027"]
bpy.context.view_layer.objects.active = font_object
font_object.location.z = 0.4
font_object.keyframe_insert("location", frame=1)
font_object.location.z = 0.54
font_object.keyframe_insert("location", frame=50)