node_kit/operators.py

56 lines
1.1 KiB
Python
Raw Normal View History

2024-02-22 10:09:34 +01:00
"""
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'
2024-02-23 16:01:16 +01:00
bl_label = 'Copy nodes'
2024-02-22 10:09:34 +01:00
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'
2024-02-23 16:01:16 +01:00
bl_label = 'Paste nodes'
2024-02-22 10:09:34 +01:00
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)