0
$\begingroup$

I have mesh with shapekeys and drivers on said shapekeys which are controlled with armature bones. All shapekeys are set to scripted expression and single prop which is set to said armature. I'm trying to reparent said mesh to new armature, which isn't hard but now shapekey drivers are still reading values on old armature instead on new one(same bones and setup).

Even doing that isn't hard, as seen in picture, but its just not fun way to do it as i have dozen of shapekeys. How to do that with script or something to speed things up and make them less tedious?

I did check around the net to see if someone had solved my issue but things that i did find are kinda old and ware not working on blender 3.3.enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

Change Shape Key driver first variables target

To view more details, go to: Modify driver target (or any property)

# select some objects and run in object mode

import bpy

# get shape keys fcurves of a object
def get_shape_key_fcurves(obj):
    try:
        return obj.data.shape_keys.animation_data.drivers
    except: return None

def change_driver_target(fc, target_type, target):
    dr_vars = fc.driver.variables
    if dr_vars:
        var = dr_vars[0]
        var.type = "SINGLE_PROP"
        var.targets[0].id_type = target_type
        var.targets[0].id = target


objects = bpy.data.objects
target_type = "ARMATURE"
target = objects["Armature"].data

for obj in bpy.context.selected_objects:
    fcs = get_shape_key_fcurves(obj)
    if fcs is None: continue

    for fc in fcs:
        change_driver_target(fc, target_type, target)
$\endgroup$

You must log in to answer this question.

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