Cleanup: Better perator names and description, moved format logic to its own file
parent
94627debc6
commit
cbf1ea64e6
|
@ -1,29 +1,13 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
from .. import utils
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
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"""
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
21
operators.py
21
operators.py
|
@ -14,9 +14,10 @@ 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 .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
|
||||||
|
from .formats import dump_nkit_format, parse_nkit_format
|
||||||
|
|
||||||
|
|
||||||
class NODEKIT_OT_copy(Operator):
|
class NODEKIT_OT_copy(Operator):
|
||||||
|
@ -36,8 +37,6 @@ class NODEKIT_OT_copy(Operator):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
pprint(ntree_data)
|
|
||||||
|
|
||||||
context.window_manager.clipboard = dump_nkit_format(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")
|
||||||
|
@ -52,9 +51,7 @@ class NODEKIT_OT_copy_tree(Operator):
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
ntree = context.space_data.edit_tree
|
ntree = context.space_data.edit_tree
|
||||||
ntree_data = dump_nodes(ntree)
|
ntree_data = dict(ntree)
|
||||||
|
|
||||||
pprint(ntree_data)
|
|
||||||
|
|
||||||
context.window_manager.clipboard = dump_nkit_format(ntree_data)
|
context.window_manager.clipboard = dump_nkit_format(ntree_data)
|
||||||
|
|
||||||
|
@ -78,7 +75,8 @@ class NODEKIT_OT_paste(Operator):
|
||||||
|
|
||||||
class NODEKIT_OT_remap_node_group_duplicates(Operator):
|
class NODEKIT_OT_remap_node_group_duplicates(Operator):
|
||||||
bl_idname = "node_kit.remap_node_group_duplicates"
|
bl_idname = "node_kit.remap_node_group_duplicates"
|
||||||
bl_label = "Remap Node Groups Duplicates"
|
bl_label = "Clean Node Groups Duplicates"
|
||||||
|
bl_description = "Remap Node Groups duplicates to the latest imported version"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
selection: EnumProperty(
|
selection: EnumProperty(
|
||||||
|
@ -139,7 +137,8 @@ class NODEKIT_OT_remap_node_group_duplicates(Operator):
|
||||||
|
|
||||||
class NODEKIT_OT_update_nodes(Operator):
|
class NODEKIT_OT_update_nodes(Operator):
|
||||||
bl_idname = "node_kit.update_nodes"
|
bl_idname = "node_kit.update_nodes"
|
||||||
bl_label = "Update Nodes"
|
bl_label = "Update Nodes from Library"
|
||||||
|
bl_description = "Overrides node group using the latest version from Asset Library"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
selection: EnumProperty(
|
selection: EnumProperty(
|
||||||
|
@ -249,7 +248,8 @@ class NODEKIT_OT_update_nodes(Operator):
|
||||||
|
|
||||||
class NODEKIT_OT_pack_nodes(Operator):
|
class NODEKIT_OT_pack_nodes(Operator):
|
||||||
bl_idname = "node_kit.pack_nodes"
|
bl_idname = "node_kit.pack_nodes"
|
||||||
bl_label = "Pack Nodes"
|
bl_label = "Pack Modifiers as Nodes"
|
||||||
|
bl_description = "Pack Geometry Nodes modifiers stack as a single node tree"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
@ -259,7 +259,8 @@ class NODEKIT_OT_pack_nodes(Operator):
|
||||||
|
|
||||||
class NODEKIT_OT_unpack_nodes(Operator):
|
class NODEKIT_OT_unpack_nodes(Operator):
|
||||||
bl_idname = "node_kit.unpack_nodes"
|
bl_idname = "node_kit.unpack_nodes"
|
||||||
bl_label = "Unpack Nodes"
|
bl_label = "Unpack Nodes as Modifiers"
|
||||||
|
bl_description = "Unpack node tree as Geometry Nodes modifiers"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
|
Loading…
Reference in New Issue