0
$\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$
0
$\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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.