1
$\begingroup$

This is my code right now:

import bpy

for k in bpy.data.shape_keys.keys() :
    bpy.data.shape_keys[k].key_blocks["Opened"].value = 0

It change the value of all shapekeys keyblocks with the name "Opened" to 0. I do that because I model a bag and I want 2 versions of it, opened and closed, for rendering. The problem is the I don't want to change the shapekeys in other scenes, and with this current code that's what's happening. I need a way to access shape_keys keyblocks that are only applied to the objects in the collection of my choice. How may I do that?

$\endgroup$

1 Answer 1

1
$\begingroup$

Get the collection by its name and loop over mesh objects (or others that have shape keys) in it to reach their shape keys.

import bpy

collection_name = "Collection"

collection = bpy.data.collections.get( collection_name )

if collection:
    for obj in [o for o in collection.objects if o.type == 'MESH']:
        key_block = obj.data.shape_keys.key_blocks.get( "Opened" )
        if key_block:
            key_block.value = 0
$\endgroup$

You must log in to answer this question.

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