Currently I have a default cube and 400 frames.

Here's what I have working without keyframing

import bpy

current_scene = bpy.context.scene

default_cube = current_scene.objects['default_cube']

def update_scene():
    current_frame_value = current_scene.frame_current

    if current_frame_value < 100:
        default_cube.scale.x = .05
    elif current_frame_value < 200:
         default_cube.scale.x = .08
    elif current_frame_value > 300:
        default_cube.scale.x = .3
        default_cube.scale = 1


print('I work!')

The problem I'm having with the non-keyframe method is there isn't any interpolation between the scaling and I intend do this for thousands of frames. What is a good method to use keyframes programmatically to achieve interpolation?

https://docs.blender.org/manual/en/latest/editors/python_console.html Blender 2.8 doesn't reference anywhere.


Figured it out!

here's how to use the python API to set it.

# X, Y, and Z location to set
default_cube.location = 0.0, 0.0, 0.0
# Set the keyframe with that location, and which frame.
default_cube.keyframe_insert(data_path="location", frame=1)

# do it again!
default_cube.location = 3.0, 2.0, 1.0
# setting it for frame 10
default_cube.keyframe_insert(data_path="location", frame=10)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.