0
$\begingroup$

I honestly can not figure this out...

How do I add a keyframe frame for each time this loop executes?

Right now this code adds a keyframe, but it doesn't add the modifier to the keyframe I think.

import bpy


bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 
0), scale=(1, 1, 1))
bpy.ops.object.modifier_add(type='SCREW')



bpy.context.scene.frame_current = 1
bpy.ops.anim.keyframe_insert_menu(type='LocRotScaleCProp')



for t in range(1,10):

  bpy.context.scene.frame_current = t
  bpy.data.collections['Collection'].objects['Cube'].modifiers['Screw'].screw_offset = t
  bpy.ops.anim.keyframe_insert_menu(type='LocRotScaleCProp')
$\endgroup$
1
  • $\begingroup$ and why do you think this codes adds a keyframe? $\endgroup$
    – Chris
    Feb 21, 2022 at 9:03

1 Answer 1

0
$\begingroup$

I am using Blender 3.0.1

Yeah, type='LocRotScaleCProp' won't work for modifiers.

Do it this way:

# -- Delete all
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)

# -- New cube
bpy.ops.mesh.primitive_cube_add(size=1)
obj = bpy.context.active_object
# -- Add modifier
bpy.ops.object.modifier_add(type='SCREW')

bpy.context.scene.frame_current = 1

for t in range(0, 10):
    bpy.context.scene.frame_current = t
    obj.modifiers['Screw'].screw_offset = t
    obj.keyframe_insert(data_path='modifiers["Screw"].screw_offset', frame=t)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .