Copy/Paste operators cleanup
parent
9940a9c8ca
commit
4e029c59a2
|
@ -31,7 +31,7 @@ def get_bl_object(data):
|
||||||
return bpy.context.object.modifiers.active.node_group
|
return bpy.context.object.modifiers.active.node_group
|
||||||
|
|
||||||
|
|
||||||
def dump(ob):
|
def dump_nodes(ob):
|
||||||
"""Generic Recursive Dump, convert any object into a dict"""
|
"""Generic Recursive Dump, convert any object into a dict"""
|
||||||
Dumper.pointers.clear()
|
Dumper.pointers.clear()
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ def dump(ob):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def load(data, bl_object=None):
|
def load_nodes(data, bl_object=None):
|
||||||
"""Generic Load to create an object from a dict"""
|
"""Generic Load to create an object from a dict"""
|
||||||
|
|
||||||
Dumper.pointers.clear()
|
Dumper.pointers.clear()
|
||||||
|
|
17
operators.py
17
operators.py
|
@ -15,7 +15,7 @@ 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 node_kit.core.node_tree import NodeTree
|
||||||
from .core.dumper import dump, load
|
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
|
||||||
|
|
||||||
|
@ -23,39 +23,44 @@ from .core.pack_nodes import combine_objects, extract_objects
|
||||||
class NODEKIT_OT_copy(Operator):
|
class NODEKIT_OT_copy(Operator):
|
||||||
bl_idname = "node_kit.copy_node_tree"
|
bl_idname = "node_kit.copy_node_tree"
|
||||||
bl_label = "Copy nodes"
|
bl_label = "Copy nodes"
|
||||||
|
bl_description = "Copy nodes to system clipboard"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
select_only: BoolProperty(default=True)
|
select_only: BoolProperty(default=True) # TODO: Expose/rework this property properly - No F3 panel in Node Editor - Only F9
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
ntree = context.space_data.edit_tree
|
ntree = context.space_data.edit_tree
|
||||||
if self.select_only:
|
if self.select_only:
|
||||||
ntree_data = {
|
ntree_data = {
|
||||||
"nodes": dump(
|
"nodes": dump_nodes(
|
||||||
[n for n in ntree.nodes if n.select]
|
[n for n in ntree.nodes if n.select]
|
||||||
), # [dump(n) for n in ntree.nodes if n.select],
|
), # [dump(n) for n in ntree.nodes if n.select],
|
||||||
"links": dump(
|
"links": dump_nodes(
|
||||||
[l for l in ntree.links if l.from_node.select and l.to_node.select]
|
[l for l in ntree.links if l.from_node.select and l.to_node.select]
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
ntree_data = dump(ntree)
|
ntree_data = dump_nodes(ntree)
|
||||||
|
|
||||||
pprint(ntree_data)
|
pprint(ntree_data)
|
||||||
|
|
||||||
context.window_manager.clipboard = json.dumps(ntree_data)
|
context.window_manager.clipboard = json.dumps(ntree_data)
|
||||||
|
|
||||||
|
self.report({"INFO"}, f"Copied 5 selected nodes to system clipboard")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class NODEKIT_OT_paste(Operator):
|
class NODEKIT_OT_paste(Operator):
|
||||||
bl_idname = "node_kit.paste_node_tree"
|
bl_idname = "node_kit.paste_node_tree"
|
||||||
bl_label = "Paste nodes"
|
bl_label = "Paste nodes"
|
||||||
|
bl_description = "Paste nodes from system clipboard"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
ntree_data = json.loads(context.window_manager.clipboard)
|
ntree_data = json.loads(context.window_manager.clipboard)
|
||||||
load(ntree_data, context.space_data.edit_tree)
|
load_nodes(ntree_data, context.space_data.edit_tree)
|
||||||
|
|
||||||
|
self.report({"INFO"}, f"5 node(s) pasted from system clipboard")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue