0
$\begingroup$

I'm working on a popup menu to accelerate lip syncing within Blender Grease Pencil. I have a popup menu with a selection of all of the lip sync sounds an animator needs (ex. of mouth selection options - Menu Option 1: Silent,M,B; Menu Option 2: S,T,Ch; Menu Option 3: E; etc.).

I've created several images and keyframed them using the TimeOffset Modifier. The action I want is when you click one of the popup menu options, the TimeOffset changes its frame based on the selection you've chosen and then a keyframe is inserted. I have the selection process working, but not the keyframing part.

Here is the code for those two actions for one of the menu's selections. I would need to duplicate these lines for every offset frame and change the offset at the end of the first line. The first line works, but I can't get the second one to insert a keyframe after the first action occurs. Thanks for any help you can provide!

bpy.context.object.grease_pencil_modifiers["TimeOffset"].offset = 1
bpy.context.object.grease_pencil_modifiers["TimeOffset"].offset.keyframe_insert("frame",frame=bpy.context.scene.frame_current)

EDIT: Thanks to Chris' response below, I was able to get it to work with the following code. "Offset = 2" refers to the frame in the TimeOffset modifer:

offset_mod = bpy.data.objects["GPencil"].grease_pencil_modifiers["TimeOffset"]

offset_mod.offset = 2
offset_mod.keyframe_insert(data_path="offset", frame = current_frame)
$\endgroup$
3
  • $\begingroup$ normally you use the data_path for keyframe insert, so i think "frame" is wrong here. Should be something like "offset" (i didn't test, sorry). So this is how a key_frame_insert should look like: obj.keyframe_insert(data_path='location', frame=0) $\endgroup$
    – Chris
    Commented Nov 11, 2022 at 5:04
  • $\begingroup$ Thanks for your help! I was able to get it to work. I've posted the revised code in the original message. $\endgroup$
    – David
    Commented Nov 11, 2022 at 14:06
  • $\begingroup$ Feel free to post your edit as an answer if it solves your problem. You can answer your own question and accept it so it's marked with a green arrow and other people can find it easily. $\endgroup$
    – Blunder
    Commented Nov 11, 2022 at 15:40

1 Answer 1

1
$\begingroup$

Thanks for the help! Here is the code that worked for me:

offset_mod = bpy.data.objects["GPencil"].grease_pencil_modifiers["TimeOffset"]

offset_mod.offset = 2
offset_mod.keyframe_insert(data_path="offset", frame = current_frame)
$\endgroup$

You must log in to answer this question.

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