I am trying to make a simple panel with buttons for snapping bones between IK and FK configurations, and I need to change attributes of bone constraints with python scripting.

I can quite easily change something like the Influence of a constraint this way, however I am a little lost when it comes to executing/applying/pressing the Disable and Keep Transform button through script.

I found the operator: bpy.ops.constraint.disable_keep_transform()
and I know you should be able to use "Context Override" on the operator to feed it the appropriate context
(found here: https://docs.blender.org/api/current/bpy.ops.html#overriding-context)

I have tried to copy "similiar" solutions from other people like in this question:
How do I reset a specific bone's "Stretch To" Rest Length, via code?
but I havn't been able to find much information about how these operators and the "Context Override" works.

I feel like I am close.. but someone who knows how these operators work would be a big help.

So the simple question: What context does the disable_keep_transform() operator need?

  • 1
    $\begingroup$ related: poll() failed, context incorrect? $\endgroup$
    – brockmann
    Jun 15 '20 at 11:56
  • $\begingroup$ See first part of this answer which is pretty much disable constraint (set influence to zero) and keep transform. Otherwise imagine that the operator override needs a "constraint" member which is present in PROPERTIES space but not elsewhere. Similarly blender.stackexchange.com/questions/19602/… $\endgroup$
    – batFINGER
    Jun 15 '20 at 12:26
  • $\begingroup$ So if I change the "area" attribute of the override context to one with a "PROPERTIES" type then it seems to work, however I'm currently just doing a for-loop to find the appropriate area, like this: for area in bpy.context.screen.areas : if area.type == "PROPERTIES" : override["area"] = area .. Is there a better way of getting the correct area type for the override? $\endgroup$
    – CPCN
    Jun 16 '20 at 15:54
  • $\begingroup$ Also another problem I didn't notice is that the disable_keep_transform() operator needs the specific bone constraint visible somewhere on screen to work.. meaning it doesn't work if the bone constraint tab of the properties editor is not part of the workspace and if the specific bone with the constraint is not selected and active. Is there something I'm missing? This seems increasingly insurmountable and absurd. $\endgroup$
    – CPCN
    Jun 16 '20 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.