Okay, I’m setting up UI elements to control custom properties on a pose bone, which drive shapekeys of the mesh. That part works good. The problem comes when I add clear buttons, to clear out a group of properties. The properties are cleared, but the mesh shapekeys don’t update until I make any other change. Then they snap back to their default position.
How do I force the mesh’s drivers to reevaluate after I’ve cleared the property values?
Neither scene.update() or the new depsgraph seem to do the trick.
As a possibility is there a bpy.ops function to set a custom property value? From my thinking that would force the update, whereas setting the value directly doesn’t.
Here’s the code for the operator that clears the values…
class ClearProperties(bpy.types.Operator):
"""Zero out a group of properties
"""
bl_idname = 'pose.clear_attr_' + sadie_rig
bl_label = 'Clear'
bl_options = {'UNDO'}
bone = bpy.props.StringProperty(name = 'Bone')
props = bpy.props.StringProperty(name = 'Properties')
def execute(self, context):
pose_bones = context.active_object.pose.bones
Props = self.props.split(',')
Bone = self.bone
if pose_bones.get(Bone):
for Prop in Props:
if pose_bones[Bone].get(Prop):
pose_bones[Bone][Prop] = 0.0
return {'FINISHED'}
And here’s a snippet where I set up the operator button…
<snip>
row = col.row()
row.label(text="Mouth:")
op = row.operator('pose.clear_attr_' + sadie_rig)
op.bone = parent
op.props = 'Mouth.Open,Mouth.OpenSmile,Mouth.Smile.L,Mouth.Smile.R,Mouth.Frown.L,Mouth.Frown.R,Mouth.UpDown",Mouth.Side2Side,Mouth.Twist,Mouth.Stretch,Mouth.Purse,Mouth.BareTeeth'
col.row().prop( pose_bones[ parent ], '["Mouth.Open"]', text="Open", slider = True )
col.row().prop( pose_bones[ parent ], '["Mouth.OpenSmile"]', text="Open Smile", slider = True )
</snip>
Any help is appreciated. Thanks!
Skip
<time passes>
Okay, I got it. If I end the clear function with…
pose_bones[Bone].scale[0] *= 1.0
it forces the update and works as expected. Has anybody got anything a bit more elegant?