Hello,
I want to remove all shape keys from all selected objects. I only have this script, which doesnt work.
how can I code it correctly?
import bpy
for obj in bpy.context.selected_objects :
[bpy.ops.object.shape_key_remove() for x in range(50)]
Here you go.
import bpy
for o in bpy.context.selected_objects:
if o.type == "MESH":
for k in o.data.shape_keys.key_blocks:
o.shape_key_remove(k)
3 Likes
when I run the script, it doenst work. I want to remove it from all selected objects but it only removes it from one object, the one I selected.
Hm, that’s weird. It works for me fine.
Do you get any errors after running the code?
there are no messages, it only says it failed.
I find out the problem, if i select also objects without any shape keys, the script fails and doesnt remove any shape keys.
I have over 150 objects and I want to select all bc selecting only those with shape keys would take too long.
how can you run the script with objects without any shape keys selected?
You just delete their shape-key data from the blend, basically.
My script deletes any shape-keys found on selected objects if the object is of type mesh.
all my objects are meshes. It happens to me when I also selected meshes with no shape keys.
Here I only selected 3 objects
deleting each shape key wont help me because often I work with hundrens of objects (every day)
In this case, those are errors. Please show them.
If I run the script, this is the only message I get
You’re showing the content of the Info Editor.
Please show the content of your Blender’s terminal Console instead.
After toggling the console, it should show as a separate terminal window.
Oh, I am sorry.
This is the only message I get:
Ah, apparently one or more of your object’s do not have shape-keys, which fails the script because it’s attempting to access shape-keys that do not exist. I fixed my code to only work if the selected objects’ have existing shape-keys.
import bpy
for o in bpy.context.selected_objects:
if o.type == "MESH":
if o.data.shape_keys:
for k in o.data.shape_keys.key_blocks:
o.shape_key_remove(k)
1 Like
Hi,
the script applys shape keys to the mesh that were set to zero. Is it possible to change it, so that it only applys shape keys to the mesh which are set to 1 and wont apply shape keys that are set to 0?
Done.
import bpy
for o in bpy.context.selected_objects:
if o.type == "MESH":
if o.data.shape_keys:
for k in o.data.shape_keys.key_blocks:
if k.value == 0:
o.shape_key_remove(k)
1 Like
hello,
thank you but If I run the script,
shape keys which have a value of 0 will be applied to 1.
I want all values to stay the same when removing all shape keys, could you change that?