2
$\begingroup$

I'm trying to automate some processes. How do I "Reset" a "Stretch To" constraint in Blender, using python scripting. I copied the code that appeared in the "Info" window after executing the action manually. but when I used

bpy.ops.constraint.stretchto_reset(constraint="Stretch To", owner='BONE')

it does not work. Is there specific code references I need to import? (I.E.: import bpy, import mathutls , etc.) Or is there some qualifiers I need to add? Maybe about the specific bone? If so Where?

Signed, Greenhorn

$\endgroup$

1 Answer 1

2
$\begingroup$

When running from the properties constraints panel context.constraint is defined. To run in script elsewhere we need to override context ie add constraint to the context dictionary and pass it to the operator.

c = context.copy()  # copy the context returns dic.
# add constraint to the context dictionary
c["constraint"] = context.active_pose_bone.constraints['Stretch To']
# override context by passing dic as first argument
bpy.ops.constraint.stretchto_reset(c, constraint="Stretch To", owner='BONE')

Note: the code above is using the selected and active pose bone. There are numerous otherways to select and send a particular pose bone to the operator.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .