Python: Checking whether a certain shapekey exists at active mesh I want to check whether a certain shapekey exists at the active mesh. How can I do that?
(Background: I have written a script, which dumps all shapekeys of a mesh with the associated values into a a textfile. Another scripts reads this files and assigns the values back to another mesh of a newer version. If the set of defined shapekeys changes, the latter scripts fails with
&quot;shapekey not found&quot;. I want to check for this case beforehand)
You can test whether a collection has an item named 'foo' with 'foo' in collection. So
def active_object_has_keyblock(name):
    ob = bpy.context.active_object
    if not ob or ob.type != 'MESH':
        return False

    mesh = ob.data
    if not mesh.shape_keys:
        return False

    return name in mesh.shape_keys.key_blocks