56 lines
1.1 KiB
Python
56 lines
1.1 KiB
Python
"""
|
|
This module contains all addons operators
|
|
|
|
:author: Autour de Minuit
|
|
:maintainers: Florentin LUCE
|
|
:date: 2024
|
|
"""
|
|
|
|
import json
|
|
import bpy
|
|
|
|
from node_kit.core.node_tree import NodeTree
|
|
|
|
|
|
class NODEKIT_OT_copy(bpy.types.Operator):
|
|
bl_idname = 'node_kit.copy_node_tree'
|
|
bl_label = 'Copy node tree'
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
select_only: bpy.props.BoolProperty(default=False)
|
|
|
|
def execute(self, context):
|
|
|
|
tree = NodeTree(context.space_data.node_tree)
|
|
context.window_manager.clipboard = json.dumps(tree.to_dict(select_only=self.select_only))
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
class NODEKIT_OT_paste(bpy.types.Operator):
|
|
bl_idname = 'node_kit.paste_node_tree'
|
|
bl_label = 'Paste node tree'
|
|
|
|
def execute(self, context):
|
|
|
|
tree = NodeTree(context.space_data.node_tree)
|
|
tree.ingest_dict(json.loads(context.window_manager.clipboard))
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
|
classes = (
|
|
NODEKIT_OT_copy,
|
|
NODEKIT_OT_paste,
|
|
)
|
|
|
|
|
|
def register():
|
|
for c in classes:
|
|
bpy.utils.register_class(c)
|
|
|
|
|
|
def unregister():
|
|
for c in reversed(classes):
|
|
bpy.utils.unregister_class(c)
|