Changing shape key values with python

Hey, it’s me again…yeah x3
By now I know that if blender’s code hint says “” That actually means “” just to make everything perfectly confusing for new users like me, but trying to apply the same logic for ShapeKeys doesn’t seem to work. What I’m trying to do is find out how to change a shape key’s value to 1 and insert a key frame for it, as well as find out how many shape keys an object has.
As to finally make a script that will animate all of my shape keys for me.

Thanks in advance!

Check this:
examples of how to use the API reference docs

Get the mesh data:
me =

Number of shape keys:

Change value of ‘Key 2’ to 0.123:
me.shape_keys.key_blocks[‘Key 2’].value = 0.123

Insert keyframe:
me.shape_keys.key_blocks[‘Key 2’].keyframe_insert(data_path=“value”)

Thank you! This really helps!

Sorry for the double post, but how do I use the keyframe_insert(data_path=“value”), what value do I use?

the “value” propety is the value. You can’t specify the actual value number, you need to set the value beforehand, then keyframe it.

me.shape_keys.key_blocks[‘Key 2’].value = 0.123 # set actual value number
me.shape_keys.key_blocks[‘Key 2’].keyframe_insert(data_path=“value”) # keyframe .value property, uses the current number (as set above)