Added a magic token to ensure only plugin data can be parsed from the clipboard
parent
18f75eed25
commit
e65d6d8a75
|
@ -1,8 +1,25 @@
|
||||||
import bpy
|
import json
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
|
||||||
|
format_token = "#FMT:NODE_KIT#"
|
||||||
|
|
||||||
|
|
||||||
|
def dump_nkit_format(data: str) -> str:
|
||||||
|
return format_token + json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_nkit_format(data: str) -> str | None:
|
||||||
|
if data.startswith(format_token):
|
||||||
|
print(data[len(format_token):])
|
||||||
|
return json.loads(data[len(format_token):])
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_default(prop: bpy.types.Property):
|
def get_default(prop: bpy.types.Property):
|
||||||
"""Get the default value of a Blender property"""
|
"""Get the default value of a Blender property"""
|
||||||
|
|
|
@ -14,8 +14,7 @@ import bpy
|
||||||
from bpy.props import BoolProperty, EnumProperty
|
from bpy.props import BoolProperty, EnumProperty
|
||||||
from bpy.types import Operator
|
from bpy.types import Operator
|
||||||
|
|
||||||
# from node_kit.core.node_tree import NodeTree
|
from .core.dumper import dump_nodes, load_nodes, dump_nkit_format, parse_nkit_format
|
||||||
from .core.dumper import dump_nodes, load_nodes
|
|
||||||
from .core.node_utils import remap_node_group_duplicates
|
from .core.node_utils import remap_node_group_duplicates
|
||||||
from .core.pack_nodes import combine_objects, extract_objects
|
from .core.pack_nodes import combine_objects, extract_objects
|
||||||
|
|
||||||
|
@ -39,7 +38,7 @@ class NODEKIT_OT_copy(Operator):
|
||||||
|
|
||||||
pprint(ntree_data)
|
pprint(ntree_data)
|
||||||
|
|
||||||
context.window_manager.clipboard = json.dumps(ntree_data)
|
context.window_manager.clipboard = dump_nkit_format(ntree_data)
|
||||||
|
|
||||||
self.report({"INFO"}, f"Copied {len(selected_nodes)} selected nodes to system clipboard")
|
self.report({"INFO"}, f"Copied {len(selected_nodes)} selected nodes to system clipboard")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
@ -57,7 +56,7 @@ class NODEKIT_OT_copy_tree(Operator):
|
||||||
|
|
||||||
pprint(ntree_data)
|
pprint(ntree_data)
|
||||||
|
|
||||||
context.window_manager.clipboard = json.dumps(ntree_data)
|
context.window_manager.clipboard = dump_nkit_format(ntree_data)
|
||||||
|
|
||||||
self.report({"INFO"}, f"Copied {len(ntree.nodes)} selected nodes to system clipboard")
|
self.report({"INFO"}, f"Copied {len(ntree.nodes)} selected nodes to system clipboard")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
@ -70,7 +69,7 @@ class NODEKIT_OT_paste(Operator):
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
ntree_data = json.loads(context.window_manager.clipboard)
|
ntree_data = parse_nkit_format(context.window_manager.clipboard)
|
||||||
load_nodes(ntree_data, context.space_data.edit_tree)
|
load_nodes(ntree_data, context.space_data.edit_tree)
|
||||||
|
|
||||||
self.report({"INFO"}, f"X node(s) pasted from system clipboard") # TODO: Ge the number of parsed nodes returned
|
self.report({"INFO"}, f"X node(s) pasted from system clipboard") # TODO: Ge the number of parsed nodes returned
|
||||||
|
|
Loading…
Reference in New Issue