""" 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 nodes' 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 nodes' 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)