Mute/unmute IK via Python API

I’m trying to mute/unmute an IK constraint via Python, but unfortunately, the change is not applied.

def update_function(group, context):
    pose =["Armature"].pose
    pose.bones["Gripper Core Bone"].constraints["IK"].mute = not group.enable_ik

Any ideas why this does not work? The “eye” icon in the properties menu does update.

I’m using the Blender 2.80 beta.

This script works, but it doesn’t update until you update the scene by grabbing the bone, weird, maybe this is a depsgraph bug?

What you want to do is set the influence of the constraint like this:

def update_function(group, context):
    pose =["Armature"].pose
    pose.bones["Gripper Core Bone"].constraints["IK"].influence = not group.enable_ik

This should work!

I think controlling the influence is a better choice, too: it’s more flexible, maybe you want to set a smooth transition by controlling it with a float variable/channel.

As far as why the first thing doesn’t work: the IK constraint has a weird relationship with the other constraints, because it requires the computer to do a sort of backwards propagation of the data - the parents follow the children. So, no matter where in the stack the constraint lies, it is always evaluated first. I imagine the mute control was not evaluated during this step, leading to what looks like a bug. It may be intended behavior though, for all I know!

Also: out of curiosity, why turn the constraint on and off? If you’re doing IK/FK switching, there’s a better way. You need three bone chains: one deform chain, one FK control chain, and one IK control chain. The IK control is always on, and the deform chain copies the transforms of either the IK or FK chains based on the animator’s input. Rigify does it like this, with a little added spice, using tweak bones between the deform bones to give the animator even more control.

Thanks. Setting the Influence to 0 seems to work.

I also found another solution to this particular problem. Removing and re-adding the IK constraint.

def ik_enable_property_update(group, context):
    pose =["Armature"].pose
    constraints = pose.bones["Gripper Core Bone"].constraints
    if not group.enable_ik:
        constraint = constraints["IK"]
        constraint ="IK") = context.scene.objects['Target 2 Helper']
        constraint.use_rotation = True

I’m using this to build a industrial robot animation tool, similar to what Autodesk is doing with MIMIC

Besides from using the IK to control the robot pose, I also want to set the bone/joint rotations from the actual robot state. I guess the Rigify solution with combined IK and FK would help me in that case.