Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script to delete all shapes where vertices only move a distance smaller than a given threshold.
- #
- # pruneLength and basisName should be defined by the user.
- #
- # This script assumes that all the shapes are relative to a single basis shape key.
- # You must define the name of the basis shape key in basisName below.
- # Alter pruneLength to give a threshold below which shape movement is ignored.
- import bpy
- def deleteShapeByName(obj, shapeName):
- iShape = obj.data.shape_keys.key_blocks.keys().index(shapeName)
- obj.active_shape_key_index = iShape
- bpy.ops.object.shape_key_remove()
- ###
- # User-defined constants
- basisName = 'Basis'
- pruneLength = 0.0001
- #
- print('###')
- bpy.ops.object.mode_set(mode='OBJECT')
- obj = bpy.context.object
- basisShape = obj.data.shape_keys.key_blocks[basisName]
- shapesToDelete = []
- numberOfShapes = len(obj.data.shape_keys.key_blocks)
- # Find the names of shape keys where none of the keys move more than pruneLength
- for shape in obj.data.shape_keys.key_blocks:
- noMovement = True
- if shape != basisShape:
- for v in obj.data.vertices:
- movement = (shape.data[v.index].co - basisShape.data[v.index].co).length
- if movement > pruneLength:
- noMovement = False
- break
- if noMovement:
- shapesToDelete.append(shape.name)
- for shapeName in shapesToDelete:
- deleteShapeByName(obj, shapeName)
- print(len(shapesToDelete), 'shape keys deleted from', numberOfShapes)
Add Comment
Please, Sign In to add comment