Created
January 3, 2024 15:49
-
-
Save nabesakarenders/002781a888af996ec733aeff67ea81b2 to your computer and use it in GitHub Desktop.
Shows a little panel to mute shape keys matching a specific filter. Mutes all if no filter set. Made with the help of ChatGPT because my Python sucks!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "Mute/Unmute Shapekeys", | |
"author": "Fab3DX, Nabesaka, ChatGPT", | |
"version": (1, 0), | |
"blender": (3, 40, 0), | |
"location": "View3D > Tools > Mute/Unmute Shapekeys", | |
"description": "Mute and unmute shapekeys on the selected object", | |
"warning": "", | |
"category": "Object" | |
} | |
import bpy | |
PROPS = [ | |
('filter', bpy.props.StringProperty(name='Filter', default='')), | |
] | |
def shapekey_visibility(context, value, filter=''): | |
if context.active_object: | |
obj = context.active_object | |
if obj.data.shape_keys: | |
for shape_key in obj.data.shape_keys.key_blocks: | |
if filter == "" : | |
shape_key.mute = value | |
else : | |
if filter not in shape_key.name: | |
shape_key.mute = value | |
else: | |
self.report({'ERROR'}, "The active object has no shapekeys.") | |
return {'CANCELLED'} | |
else: | |
self.report({'ERROR'}, "Please select an object before running the script.") | |
return {'CANCELLED'} | |
return {'FINISHED'} | |
class MUTE_OT_mute_shapekeys(bpy.types.Operator): | |
"""Mutes all shapekeys on the active object""" | |
bl_idname = "object.mute_shapekeys" | |
bl_label = "Mute Shapekeys" | |
def execute(self, context): | |
result = shapekey_visibility(context, True, context.scene.filter) | |
return result | |
class UNMUTE_OT_unmute_shapekeys(bpy.types.Operator): | |
"""Unmutes all shapekeys on the active object""" | |
bl_idname = "object.unmute_shapekeys" | |
bl_label = "Unmute Shapekeys" | |
def execute(self, context): | |
result = shapekey_visibility(context, False, context.scene.filter) | |
return result | |
class MuteUnmuteShapeKeysPanel(bpy.types.Panel): | |
"""Creates a panel in the 3D View tools panel""" | |
bl_label = "Mute & Unmute Shape Keys" | |
bl_idname = "VIEW3D_PT_Mute_Unmute_Shapekeys" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = "Tools" | |
def draw(self, context): | |
col = self.layout.column() | |
for(prop_name, _) in PROPS: | |
row = col.row() | |
row.prop(context.scene, prop_name) | |
col.operator("object.mute_shapekeys", text="Mute Shapekeys") | |
col.operator("object.unmute_shapekeys", text="UnMute Shapekeys") | |
CLASSES = [ | |
MUTE_OT_mute_shapekeys, | |
UNMUTE_OT_unmute_shapekeys, | |
MuteUnmuteShapeKeysPanel, | |
] | |
def register(): | |
for (prop_name, prop_value) in PROPS: | |
setattr(bpy.types.Scene, prop_name, prop_value) | |
for cls in CLASSES: | |
bpy.utils.register_class(cls) | |
def unregister(): | |
for (prop_name, _) in PROPS: | |
delattr(bpy.types.Scene, prop_name) | |
for cls in CLASSES: | |
bpy.utils.unregister_class(cls) | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment