Mute shape keys with partial name

I am a Python noob and I’ve Googled this to death to try and reverse engineer, for hours with no luck. I am hoping somebody can help.

bpy.context.active_object.data.shape_keys.key_blocks[“shapekeyname”].mute = True

What I want to do is to mute the shape keys of multiple selected objects, but only if the shape key contains certain letters.

Example:
Object 1 shape key = abcTEST123
Object 2 shape key = defTEST456
Object 3 shape key = ghiTEST789

How do I apply .mute = True to all, but only if the selected object’s shape key’s name contains TEST ?

Ugly but functional. someone should be able to clean this up in a follow up post but thought i’d offer a quick solution:

import bpy

my_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']

key_filter = "2"

my_keys = [[kb for kb in obj.data.shape_keys.key_blocks if key_filter in kb.name] for obj in my_objs]

print(my_keys)

for obj_keys in my_keys:
    for k in obj_keys:
        k.mute = True
2 Likes

It works! I wouldn’t have figured that out, so it just goes to show how little I know. Thank you very much Nezumi.