Expose ops copy-move keys to layer in menus
3.0.2 - changed: Exposed `Copy/Move Keys To Layer` in Dopesheet(Gpencil), in right clic context menu and `Keys` menu.gpv2
parent
810256f5cb
commit
47b9b68e9e
|
@ -17,20 +17,27 @@ def get_layer_list(self, context):
|
||||||
|
|
||||||
class GPTB_OT_duplicate_send_to_layer(Operator) :
|
class GPTB_OT_duplicate_send_to_layer(Operator) :
|
||||||
bl_idname = "gp.duplicate_send_to_layer"
|
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
|
# important to have the updated enum here as bl_property
|
||||||
bl_property = "layers_enum"
|
bl_property = "layers_enum"
|
||||||
|
|
||||||
|
|
||||||
layers_enum : bpy.props.EnumProperty(
|
layers_enum : bpy.props.EnumProperty(
|
||||||
name="Duplicate to layers",
|
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,
|
items=get_layer_list,
|
||||||
options={'HIDDEN'},
|
options={'HIDDEN'},
|
||||||
)
|
)
|
||||||
|
|
||||||
delete_source : bpy.props.BoolProperty(default=False, options={'SKIP_SAVE'})
|
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
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
return context.object and context.object.type == 'GPENCIL'\
|
return context.object and context.object.type == 'GPENCIL'\
|
||||||
|
@ -56,16 +63,16 @@ class GPTB_OT_duplicate_send_to_layer(Operator) :
|
||||||
|
|
||||||
replaced = len(to_replace)
|
replaced = len(to_replace)
|
||||||
|
|
||||||
## remove overlapping frames
|
## Remove overlapping frames
|
||||||
for f in reversed(to_replace):
|
for f in reversed(to_replace):
|
||||||
target_layer.frames.remove(f)
|
target_layer.frames.remove(f)
|
||||||
|
|
||||||
## copy original frames
|
## Copy original frames
|
||||||
for f in selected_frames:
|
for f in selected_frames:
|
||||||
target_layer.frames.copy(f)
|
target_layer.frames.copy(f)
|
||||||
sent = len(selected_frames)
|
sent = len(selected_frames)
|
||||||
|
|
||||||
## delete original frames as an option
|
## Delete original frames as an option
|
||||||
if self.delete_source:
|
if self.delete_source:
|
||||||
for f in reversed(selected_frames):
|
for f in reversed(selected_frames):
|
||||||
act_layer.frames.remove(f)
|
act_layer.frames.remove(f)
|
||||||
|
@ -73,9 +80,6 @@ class GPTB_OT_duplicate_send_to_layer(Operator) :
|
||||||
mess = f'{sent} keys copied'
|
mess = f'{sent} keys copied'
|
||||||
if replaced:
|
if replaced:
|
||||||
mess += f' ({replaced} replaced)'
|
mess += f' ({replaced} replaced)'
|
||||||
|
|
||||||
# context.view_layer.update()
|
|
||||||
# bpy.ops.gpencil.editmode_toggle()
|
|
||||||
|
|
||||||
mod = context.mode
|
mod = context.mode
|
||||||
bpy.ops.gpencil.editmode_toggle()
|
bpy.ops.gpencil.editmode_toggle()
|
||||||
|
@ -109,9 +113,6 @@ class GPTB_OT_duplicate_send_to_layer(Operator) :
|
||||||
|
|
||||||
addon_keymaps = []
|
addon_keymaps = []
|
||||||
def register_keymaps():
|
def register_keymaps():
|
||||||
# pref = get_addon_prefs()
|
|
||||||
# if not pref.kfj_use_shortcut:
|
|
||||||
# return
|
|
||||||
addon = bpy.context.window_manager.keyconfigs.addon
|
addon = bpy.context.window_manager.keyconfigs.addon
|
||||||
km = addon.keymaps.new(name = "Dopesheet", space_type = "DOPESHEET_EDITOR")
|
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)
|
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()
|
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 = (
|
classes = (
|
||||||
GPTB_OT_duplicate_send_to_layer,
|
GPTB_OT_duplicate_send_to_layer,
|
||||||
)
|
)
|
||||||
|
@ -139,12 +146,19 @@ def register():
|
||||||
|
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
bpy.utils.register_class(cls)
|
bpy.utils.register_class(cls)
|
||||||
|
|
||||||
register_keymaps()
|
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():
|
def unregister():
|
||||||
if bpy.app.background:
|
if bpy.app.background:
|
||||||
return
|
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()
|
unregister_keymaps()
|
||||||
|
|
||||||
for cls in reversed(classes):
|
for cls in reversed(classes):
|
||||||
bpy.utils.unregister_class(cls)
|
bpy.utils.unregister_class(cls)
|
|
@ -4,7 +4,7 @@ bl_info = {
|
||||||
"name": "GP toolbox",
|
"name": "GP toolbox",
|
||||||
"description": "Tool set for Grease Pencil in animation production",
|
"description": "Tool set for Grease Pencil in animation production",
|
||||||
"author": "Samuel Bernou, Christophe Seux",
|
"author": "Samuel Bernou, Christophe Seux",
|
||||||
"version": (3, 0, 1),
|
"version": (3, 0, 2),
|
||||||
"blender": (4, 0, 0),
|
"blender": (4, 0, 0),
|
||||||
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
"location": "Sidebar (N menu) > Gpencil > Toolbox / Gpencil properties",
|
||||||
"warning": "",
|
"warning": "",
|
||||||
|
|
Loading…
Reference in New Issue