Controlling specific constraints on selected bones

Hello,is there a way for disabling/toggling/removing specific constraints on specific selected bones in the armature??

I’m currently having some thoughts on improving my workflow with rigging.
Im using rigify for a game rig, neaded some tweaks but it worcks just fine ;]
The problem starts every time when the armature is generated, i need to disable all the “Stretch To” constraints manually going over every bone (60+ usually) .-.
You can guess that’s a task that should be automated do to its repetitive nature ^^"
Is there any addon to help improve ringing or any script to automate this type of proces?

THX

import bpy

for b in bpy.context.active_object.pose.bones:
for c in b.constraints:
if c.type == “STRETCH_TO”:
c.rest_length = 0

This will reset all your stretch to lengths when you run it. A little python goes a long way.

thx for the quick reply ;]
i’m new to python so my knowledge is limited XD
hmm but something doesnt seams to work :frowning:

When i select the bones in pose mode with the Stretch To constraint
run the script i get

File “C:\Users\Intel\Desktop\script_test.blend\Text.001”, line 4
for c in b.constraints:
^
IndentationError: expected an indented block

location: :-1

Python script fail, look in the console for now…

btw if i just need to disable the Stretch To constaints shoud it be mute = True ?? i want those constraint disabled so i can export the animation and rig to FBX
atm im using blender 2.79b

i’d recommend to manipulate with constraint’s influence property instead of rest_length

NB. indents are important, the armature require to be selected on script execution

stretch-to

import bpy

for b in bpy.context.active_object.pose.bones:
    for c in b.constraints:
        if c.type == "STRETCH_TO":
            c.influence = 1
1 Like

Hi,

I usually toggle the mute variable, it looks cleaner to me that way. Indentation didn’t seem to carry through in stilltrying’s post but yeah indentation is obligatory in python.

Hadrien

1 Like

hmm i see, wow there’s so much i can do bu yet so much i need to learn about this XD
And changing the influence is interesting idea.
Now need to try make it work just on selected bones ;]
from what i understand changing

for b in bpy.context.active_object.pose.bones:
to
for b in bpy.context.active_object.pose.selected_pose_bones or selected_bones ?? but i gues theres more to it XD
was reading some https://docs.blender.org/api/blender_python_api_current/
and watched few tuts on scripting in blender but honestly can’t wrap my head around it -.-

That’s really just it, but iirc it has to be “selected_pose_bones” (Blender differenciates between pose bones and edit bones, obviously they’re conceptually the same but not at the data level).