diff --git a/OP_key_duplicate_send.py b/OP_key_duplicate_send.py index 4f84a08..6c1c915 100644 --- a/OP_key_duplicate_send.py +++ b/OP_key_duplicate_send.py @@ -17,20 +17,27 @@ def get_layer_list(self, context): class GPTB_OT_duplicate_send_to_layer(Operator) : bl_idname = "gp.duplicate_send_to_layer" - bl_label = 'Duplicate and send to layer' + bl_label = 'Duplicate Send To Layer' + bl_description = 'Duplicate selected keys in active layer and send to chosen layer' # important to have the updated enum here as bl_property bl_property = "layers_enum" - layers_enum : bpy.props.EnumProperty( name="Duplicate to layers", - description="Duplicate selected keys in active layer and send them to choosen layer", + description="Duplicate selected keys in active layer and send them to chosen layer", items=get_layer_list, options={'HIDDEN'}, ) delete_source : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'}) + @classmethod + def description(cls, context, properties): + if properties.delete_source: + return f"Move selected keys in active layer to chosen layer" + else: + return f"Copy selected keys in active layer and send to chosen layer" + @classmethod def poll(cls, context): return context.object and context.object.type == 'GPENCIL'\ @@ -56,16 +63,16 @@ class GPTB_OT_duplicate_send_to_layer(Operator) : replaced = len(to_replace) - ## remove overlapping frames + ## Remove overlapping frames for f in reversed(to_replace): target_layer.frames.remove(f) - ## copy original frames + ## Copy original frames for f in selected_frames: target_layer.frames.copy(f) sent = len(selected_frames) - ## delete original frames as an option + ## Delete original frames as an option if self.delete_source: for f in reversed(selected_frames): act_layer.frames.remove(f) @@ -73,9 +80,6 @@ class GPTB_OT_duplicate_send_to_layer(Operator) : mess = f'{sent} keys copied' if replaced: mess += f' ({replaced} replaced)' - - # context.view_layer.update() - # bpy.ops.gpencil.editmode_toggle() mod = context.mode bpy.ops.gpencil.editmode_toggle() @@ -109,9 +113,6 @@ class GPTB_OT_duplicate_send_to_layer(Operator) : addon_keymaps = [] def register_keymaps(): - # pref = get_addon_prefs() - # if not pref.kfj_use_shortcut: - # return addon = bpy.context.window_manager.keyconfigs.addon km = addon.keymaps.new(name = "Dopesheet", space_type = "DOPESHEET_EDITOR") kmi = km.keymap_items.new('gp.duplicate_send_to_layer', type='D', value="PRESS", ctrl=True, shift=True) @@ -129,6 +130,12 @@ def unregister_keymaps(): addon_keymaps.clear() +def menu_duplicate_and_send_to_layer(self, context): + if context.space_data.ui_mode == 'GPENCIL': + self.layout.operator_context = 'INVOKE_REGION_WIN' + self.layout.operator('gp.duplicate_send_to_layer', text='Move Keys To Layer').delete_source = True + self.layout.operator('gp.duplicate_send_to_layer', text='Copy Keys To Layer') + classes = ( GPTB_OT_duplicate_send_to_layer, ) @@ -139,12 +146,19 @@ def register(): for cls in classes: bpy.utils.register_class(cls) + register_keymaps() + bpy.types.DOPESHEET_MT_gpencil_key.append(menu_duplicate_and_send_to_layer) + bpy.types.DOPESHEET_MT_context_menu.append(menu_duplicate_and_send_to_layer) + def unregister(): if bpy.app.background: return - + + bpy.types.DOPESHEET_MT_context_menu.remove(menu_duplicate_and_send_to_layer) + bpy.types.DOPESHEET_MT_gpencil_key.remove(menu_duplicate_and_send_to_layer) unregister_keymaps() + for cls in reversed(classes): bpy.utils.unregister_class(cls) \ No newline at end of file diff --git a/__init__.py b/__init__.py index 3dc2017..e88411a 100755 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ bl_info = { "name": "GP toolbox", "description": "Tool set for Grease Pencil in animation production", "author": "Samuel Bernou, Christophe Seux", -"version": (3, 0, 1), +"version": (3, 0, 2), "blender": (4, 0, 0), "location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties", "warning": "",