1
$\begingroup$

I have a rig with Shrinkwrap Constraints on many bones, with nearly identical parameters. When I made the shrinkwrap bone constraints I had to specify a particular object target. Now I want to change that target without going through all the trouble of selecting everything. I'd also like a variable to control whether deform is turned on for some of those bones (I think driver can do this already).

I'm a programmer, so I'm wondering if I can just use variables/custom properties somehow (for the Target in the constraint). Drivers seem to be only for numeric animation properties.

If I can set the target object as a custom property or something on the armature object, then I can have it react to a different object in the scene. No need to animate this choosiness. I only want to be able to reuse this rigged object over and over like an asset.

Is there an addon for this? Allow me to make drivers or choose properties for like anything? Custom property group with an "onchanged" might be what i need? but i wish there was an addon for this.

$\endgroup$

1 Answer 1

1
$\begingroup$

You can use the Text Editor under the Scripting Tab to easily execute script to automate your process. For example if you wanted to change the Shrinkwrap Constraint target for all the bones inside the armature named Armature.001, you can run the following script. Make sure to set new_target with an object you want as target and change armature_name.

import bpy

def set_new_shrinkwrap_target(armature_name, target):
    contraint_name = "Shrinkwrap"
    for bone in bpy.data.objects[armature_name].pose.bones:
        if not contraint_name in bone.constraints:
            continue
        bone.constraints[contraint_name].target = target

armature_name = "Armature.001"
new_target = <some new object target> #maybe bpy.context.object which is selected object
set_new_shrinkwrap_target(armature_name, new_target)

I'm not sure what you mean by "whether deform is turned on" but as a programmer I assume this should be easy: Just right click any field, in your case this deform property or the target field of the srhinkwrap constraint and choose Copy Full Data Path then paste it in the editor.

enter image description here

You will see something like this:

bpy.data.objects["Armature.001"].pose.bones["Bone.002"].constraints["Shrinkwrap"].target

That's how I was able to come up with the function, I realized I can loop over the bones of the armature. You can right click almost any field in the Blender user interface :)

$\endgroup$
2
  • $\begingroup$ ah kinda forgot full data path was very pythonic. was def consiering writing a script but thought I would have had to do alot of lookup of blender api lookup. good that this is a good shortcut for it. was kinda hoping there was an addon that does "driver on anything" to link many things to custom properties. but ofc no hard requirement on animating like a real driver. $\endgroup$
    – Shorin
    Aug 15, 2022 at 6:08
  • $\begingroup$ Yeah unfortunately afaik there is no other way. But look at the bright side, you have better control of your own script :) $\endgroup$ Aug 15, 2022 at 7:11

You must log in to answer this question.

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