Changing object property

Hi folks, I am trying to write a script that changes the values for the MHX2 rig imported into Blender from Makehuman. For instance, dropping the jaw looks like this (it’s a setting in the tools panel):

bpy.data.objects[“Fg02”][“MfaJawDropStretched”]

If I print this, the current value of MfaJawDropStretched is output. But then I try to change the value like this:

bpy.data.objects[“Fg02”][“MfaJawDropStretched”] = 1

Now the new value is output when I do print on this but nothing happens with the rig.

If I rather change the value directly in the tools panel by using the slider, that new value is also output when I print the above line. So it is the same object, but it seems to only go “one way” so to speak.

Does anyone know what I do wrong and what is the right way to do this?

(Just in case anyone wonders why I want to script this: I want to hook up a shape key to each one of the Face Units so I can fine tune the face expressions when animating. So I am writing an addon for this.)

I kind of got around it. But now I just can’t figure out how to change the value of a shape key from this script. This is how it looks so far:

import bpy

bl_info =
{
“name” : “Expressions with Shapes”,
“author” : “Per Klason <[email protected]>”,
“version” : (1, 0, 0),
“blender” : (2, 5, 7),
“location” : “View 3D > Edit Mode > Tool Shelf”,
“description” :
“Adds expressions to MHX2 using rig with shape heys”,
“warning” : “”,
“wiki_url” : “”,
“tracker_url” : “”,
“category” : “Add Mesh”,
}

def update_func(self, context):
wm = context.window_manager
JawDropStretched = 0.2 * wm.float
bpy.ops.mhx2.set_expression(units=“lowerLipBackward:0.2260&RightCheekUp:0.4020&NasolabialDeepener:0.5430&LeftCheekUp:0.6530&RightInnerBrowUp:0.4170&MouthLeftPullUp:0.2610&UpperLipStretched:0.5580&MouthRightPullUp:0.2560&LeftLowerLidUp:0.3420&JawDropStretched:” + repr(JawDropStretched) +"&RightLowerLidUp:0.5230&LeftInnerBrowUp:0.2660")
bpy.context.object.data.shape_keys.key_blocks[‘Laugh’].value = wm.float * 10
bpy.types.WindowManager.float = bpy.props.FloatProperty(
update=update_func,
name=“Laugh2”,
default=0,
)

class OBPanel(bpy.types.Panel):
bl_idname = “selected_object”
bl_space_type = ‘VIEW_3D’
bl_region_type = ‘TOOLS’
bl_context = “posemode”

bl_label = "Expressions Shapes"
bl_category = "MHX2 Runtime"
bl_options = {'DEFAULT_CLOSED'}


def draw(self, context):
    wm = context.window_manager
    layout = self.layout
    layout.row().prop(wm, 'float')

def register():
bpy.utils.register_module(name)

def unregister():
bpy.utils.unregister_module(name)

if name == “main”:
register()

As you can see, I tried with that line “bpy.context.object.data.shape_keys.key_blocks[‘Laugh’].value = wm.float * 10” but that does not work. I just can’ figure out how to access the shape key named “Laugh” while having the rig selected and in pose mode. I also tried to make a driver for the shape key but how do I make it controlled by the value of this slider in the tools panel?