From 4d6dc06e4e9ac25c423b571772d080613b3b31f9 Mon Sep 17 00:00:00 2001 From: pullusb Date: Mon, 2 Dec 2024 11:39:17 +0100 Subject: [PATCH] Remove useless pseudo groups now that there is a native group system --- OP_layer_manager.py | 85 ++++----------------------------------------- 1 file changed, 7 insertions(+), 78 deletions(-) diff --git a/OP_layer_manager.py b/OP_layer_manager.py index 09405b3..6f8e8b1 100644 --- a/OP_layer_manager.py +++ b/OP_layer_manager.py @@ -21,6 +21,7 @@ from .utils import get_addon_prefs, is_vector_close # PATTERN = r'^(?P-\s)?(?P[A-Z]{2}_)?(?P[A-Z]{1,6}_)?(?P.*?)(?P_[A-Z]{2})?(?P\.\d{3})?$' # numering PATTERN = r'^(?P-\s)?(?P[A-Z]{2}_)?(?P.*?)(?P_[A-Z]{2})?(?P\.\d{3})?$' # numering +# TODO: allow a more flexible prefix pattern def layer_name_build(layer, prefix='', desc='', suffix=''): '''GET a layer and argument to build and assign name @@ -155,13 +156,16 @@ class GPTB_OT_layer_name_build(Operator): gpl = ob.data.layers act = gpl.active if not act: - self.report({'ERROR'}, 'no layer active') + act = ob.data.layer_groups.active + + if not act: + self.report({'ERROR'}, 'No layer active') return {"CANCELLED"} layer_name_build(act, prefix=self.prefix, desc=self.desc, suffix=self.suffix) - ## Deactivate multi-selection on layer ! - ## somethimes it affect a random layer that is still considered selected + ## /!\ Deactivate multi-selection on layer ! + ## Somethimes it affect a random layer that is still considered selected # for l in gpl: # if l.select or l == act: # layer_name_build(l, prefix=self.prefix, desc=self.desc, suffix=self.suffix) @@ -169,79 +173,6 @@ class GPTB_OT_layer_name_build(Operator): return {"FINISHED"} -def grp_toggle(l, mode='TOGGLE'): - '''take mode in (TOGGLE, GROUP, UNGROUP) ''' - grp_item_id = ' - ' - res = re.search(r'^(\s{1,3}-\s{0,3})(.*)', l.name) - if not res and mode in ('TOGGLE', 'GROUP'): - # No gpr : add group prefix after stripping all space and dash - l.name = grp_item_id + l.name.lstrip(' -') - - elif res and mode in ('TOGGLE', 'UNGROUP'): - # found : delete group prefix - l.name = res.group(2) - - -class GPTB_OT_layer_group_toggle(Operator): - bl_idname = "gp.layer_group_toggle" - bl_label = "Group Toggle" - bl_description = "Group or ungroup a layer" - bl_options = {"REGISTER", "UNDO"} - - @classmethod - def poll(cls, context): - return True - - # group : StringProperty(default='', options={'SKIP_SAVE'}) - - def execute(self, context): - ob = context.object - gpl = ob.data.layers - act = gpl.active - if not act: - self.report({'ERROR'}, 'no layer active') - return {"CANCELLED"} - for l in gpl: - if l.select or l == act: - grp_toggle(l) - return {"FINISHED"} - -class GPTB_OT_layer_new_group(Operator): - bl_idname = "gp.layer_new_group" - bl_label = "New Group" - bl_description = "Create a group from active layer" - bl_options = {"REGISTER", "UNDO"} - - def execute(self, context): - ob = context.object - gpl = ob.data.layers - act = gpl.active - if not act: - self.report({'ERROR'}, 'no layer active') - return {"CANCELLED"} - - res = re.search(PATTERN, act.name) - if not res: - self.report({'ERROR'}, 'Could not create a group name, create a layer manually') - return {"CANCELLED"} - - name = res.group('name').strip(' -') - if not name: - self.report({'ERROR'}, f'No name found in {act.name}') - return {"CANCELLED"} - - if name in [l.name.strip(' -') for l in gpl]: - self.report({'WARNING'}, f'Name already exists: {act.name}') - return {"FINISHED"} - - grp_toggle(act, mode='GROUP') - n = gpl.new(name, set_active=False) - n.use_onion_skinning = n.use_lights = False - n.hide = True - n.opacity = 0 - return {"FINISHED"} - - #-## SELECTION MANAGEMENT ##-# def activate_channel_group_color(context): @@ -818,8 +749,6 @@ def unregister_keymaps(): classes=( GPTB_OT_rename_gp_layer, GPTB_OT_layer_name_build, - GPTB_OT_layer_group_toggle, - GPTB_OT_layer_new_group, GPTB_OT_select_set_same_prefix, GPTB_OT_select_set_same_color,