Shapekey not updating

Hi, I’m trying to create and manipulate a shapekey from python and it seems to get stuck until I select the mesh and click anywhere in the shapekey list, after that it works fine.

Seems like I need to update something somewhere, any ideas?

With the default cube selected run the following:

import bpy
obj = bpy.context.object
obj.shape_key_add("Basis")
key=obj.shape_key_add("new")
key.data[0].co = (1,1,1)

then from the console try:

bpy.context.object.data.shape_keys.key_blocks['new'].value = 1

Nothing will happen until you click in the shapekey list and then the corner will snap up.
After that, the corner will move on command. :confused:

Fixed. Setting active_shape_key_index works:

import bpy
obj = bpy.context.object
obj.shape_key_add("Basis")
obj.active_shape_key_index = 0
key=obj.shape_key_add("new")
key.data[0].co = (1,1,1)