Implement a clean up cp button so users can “mass delete” unwanted custom properties such as those generated by the wiggle-2 addon
Something like this:
import bpy
class DeleteBoneCustomPropsOperator(bpy.types.Operator):
"""Delete Bone Custom Properties Based on Partial String Match"""
bl_idname = "object.delete_bone_custom_props"
bl_label = "Delete Bone Custom Props"
bl_options = {'REGISTER', 'UNDO'}
# Property to hold the string to search for
search_string: bpy.props.StringProperty(
name="Search String",
description="String to search in custom property names"
)
@classmethod
def poll(cls, context):
return context.active_object and context.active_object.type == 'ARMATURE'
def execute(self, context):
armature = context.active_object
search_str = self.search_string
for bone in armature.pose.bones:
keys_to_delete = [key for key in bone.keys() if search_str in key]
for key in keys_to_delete:
del bone[key]
self.report({'INFO'}, "Custom properties containing '{}' have been deleted.".format(search_str))
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def register():
bpy.utils.register_class(DeleteBoneCustomPropsOperator)
def unregister():
bpy.utils.unregister_class(DeleteBoneCustomPropsOperator)
if __name__ == "__main__":
register()
Add the ability to delete from all armature if in armature mode or if nothing selected, or from selected bones only if in pose mode and any bone is selected.