1
$\begingroup$

I heard that using foreach_get is faster to get the values than using the normal way.

So I tried to get an array of shapekey values using the following method.

I selected the object that has the shapekey and ran it.

import bpy

context = bpy.context

ob = context.object
me = ob.data
sks = me.shape_keys

if sks:
    vals = []
    list = sks.key_blocks.foreach_get("value", vals)
    print(list)

However, Console just shows "None" and no values are retrieved.

How can I get the values correctly?

$\endgroup$

1 Answer 1

2
$\begingroup$

foreach_get fills the provided array with the values. It doesn't return anything. The array you pass needs to be the right length too.

    vals = [0.0] * len(sks.key_blocks)
    sks.key_blocks.foreach_get("value", vals)
    print(vals)
$\endgroup$

You must log in to answer this question.

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