When inserting a keyframe for constraint influence, is there a way to animate the equivalent of pressing the Set/Clear Inverse buttons in the constraint window?
i can’t find a button to Set / Clear Inverse in constraint window, where is that?
What does it do?
I’m sorry, I was presupposing a familiarity with my previous question.
It is first necessary to specify that it is a “ChildOf” constraint, and then the buttons appear. As to what they do, I’d love to find the manual page that actually explains it. From what I can tell, it’s related to the options in the popup menu when Alt-P (clear parent) is pressed.
The easy way:
bpy.ops.constraint.childof_clear_inverse(constraint=“Child Of”, owner=‘OBJECT’)
bpy.ops.constraint.childof_set_inverse(constraint=“Child Of”, owner=‘OBJECT’)
otherwise you could try to replicate the whatever these operators do. They seem to set the .inverse_matrix, not quite sure how it’s calculated, but here’s a hack that should work:
ob = bpy.context.object
con = ob.constraints['Child Of']
# clear inverse
con.inverse_matrix = Matrix() # 4x4 Unit/identity matrix
# set inverse
con.inverse_matrix = con.target.matrix_world.inverted() # is matrix_world really correct?
# If no, problems will probably occur in hierarchies of constraints...
ob.data.update()
But doesn’t that perform the set/clear operation at the time the script is executed? I was looking for a way to do it with keyframes, so that it could take place at various times during the animation.
Here’s the problem, and maybe there’s another solution. I will have one parent object with several children, and at various points in the animation I want some of the children but not others to follow the parent, with the selection of those following changing over time. And I would like to set all the required keyframes through a python script rather than manually.
The trouble I’m having is that when I play the animation and it reaches a spot where the influence is reduced to zero, the child reverts to its original position. How can I avoid that?
well, you can’t animate the inverse_matrix property. You could only write a frame change handler that runs the set / clear code at a certain frame, but that appears really hacky.
That’s what I was afraid of. I’ve been experimenting with using a handler and would prefer not to do it that way – and still haven’t gotten it right! – but I’ll keep at it. In the mean time, if anyone else has another solution, I’d love to hear it.
I will have one parent object with several children, and at various points in the animation I want some of the children but not others to follow the parent, with the selection of those following changing over time. And I would like to set all the required keyframes through a python script rather than manually.
Use an Empty to deploy a group then dynamically add and remove the children from the group as needed. So the Empty is considered the parent in this role.
Can assignments to groups be keyframed? If so, I think that would solve the problem. (Although I’m also not sure what you mean by having the Empty “deploy” the group – how is the link from the group to the Empty made?)