From dbdba0148512007956e845b1497bb269caf385cd Mon Sep 17 00:00:00 2001 From: Pullusb Date: Tue, 26 Apr 2022 12:14:09 +0200 Subject: [PATCH] Remove cycle modifier using ctrl+clic 1.4.2 - added: `Ctrl + click` on Add cycle modifier remove all cycle on all fcurves (hided option to force clean) --- CHANGELOG.md | 4 ++++ OP_setup.py | 14 +++++++++++--- __init__.py | 2 +- fn.py | 20 +++++++++++++++----- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 845f753..b9af359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +1.4.2 + +- added: `Ctrl + click` on Add cycle modifier remove all cycle on all fcurves (hided option to force clean) + 1.4.1 - changed: better filter for applying cycle modifier (prevent targeting prefix-reserved bones) diff --git a/OP_setup.py b/OP_setup.py index 284fe02..8b218ef 100644 --- a/OP_setup.py +++ b/OP_setup.py @@ -75,16 +75,24 @@ class AW_OT_autoset_axis(bpy.types.Operator): class AW_OT_create_cycles_modifiers(bpy.types.Operator): bl_idname = "autowalk.create_cycles_modifiers" bl_label = "Add Cycles Modifiers" - bl_description = "Add cycles modifier on all bones not starting with [mch, org, def]\ - \nand that are non-deforming" + bl_description = "Add cycles modifier on all bones not prefixed [mch, org, def, vis,fdl]\ + \nCtrl + Click : remove ALL Cycles modifiers on all fcurves" bl_options = {"REGISTER", "UNDO"} @classmethod def poll(cls, context): return context.object and context.object.type == 'ARMATURE' + + def invoke(self, context, event): + self.ctrl = event.ctrl + return self.execute(context) def execute(self, context): - fn.create_cycle_modifiers(context.object) + if self.ctrl: + fn.remove_all_cycles_modifier(context.object) + else: + fn.create_cycle_modifiers(context.object) + return {"FINISHED"} diff --git a/__init__.py b/__init__.py index a9b78bf..61822ae 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ bl_info = { "name": "Auto Walk", "description": "Develop a walk/run cycles along a curve and pin feets", "author": "Samuel Bernou", - "version": (1, 4, 1), + "version": (1, 4, 2), "blender": (3, 0, 0), "location": "View3D", "warning": "", diff --git a/fn.py b/fn.py index 00e77c5..90065e6 100644 --- a/fn.py +++ b/fn.py @@ -625,16 +625,22 @@ class attr_set(): # fcurve modifiers -def remove_all_cycles_modifier(): - for fc in bpy.context.object.animation_data.action.fcurves: +def remove_all_cycles_modifier(ob=None): + ob = ob or bpy.context.object + ct = 0 + for fc in ob.animation_data.action.fcurves: # if fc.data_path.split('"')[1] in selected_names: for m in reversed(fc.modifiers): if m.type == 'CYCLES': + ct += 1 + # print(f'Remove cycle mod on fcurve: {fc.data_path}') fc.modifiers.remove(m) + fc.update() + print(f'Remove cyclic modifiers on {ct} fcurve(s)') + return ct def create_cycle_modifiers(ob=None): - if not ob: - ob = bpy.context.object + ob = ob or bpy.context.object # skip bones that are on protected layers ? # protected = [i for i, l in enumerate(ob.data.layers_protected) if l] @@ -646,7 +652,7 @@ def create_cycle_modifiers(ob=None): name_list = [b.name for b in ob.data.bones] # if not b.use_deform (too limiting) re_prefix = re.compile(r'^(mch|def|org|vis|fld|ctp)[\._-]', flags=re.I) - + ct = 0 for fc in ob.animation_data.action.fcurves: if [m for m in fc.modifiers if m.type == 'CYCLES']: # skip already existing modifier @@ -665,7 +671,11 @@ def create_cycle_modifiers(ob=None): continue # print(f'Adding cycle modifier {fc.data_path}') _m = fc.modifiers.new(type='CYCLES') + ct += 1 fc.update() + + print(f'Added cyclic modifiers on {ct} fcurve(s)') + return ct ## Get collection, create if necessary def get_col(name, parent=None, create=True):