nodeslicer/core/nodeslicer/tree.py
2026-05-14 21:28:17 +03:00

89 lines
4.5 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
import bpy
from bpy.types import NodeTree, Operator, Menu
from ...registry import register_class
if TYPE_CHECKING:
from bpy.stub_internal.rna_enums import OperatorReturnItems
@register_class
class SLICETREE_NodeTree(NodeTree):
bl_idname = "SLICETREE_NodeTree"
bl_label = "NodeSlicer Tree"
bl_icon = "NODETREE"
@register_class
class SLICENODE_OT_Execute(Operator):
bl_idname = "slicenode.execute"
bl_label = "Execute"
bl_description = "Execute"
node_name: bpy.props.StringProperty() # pyright: ignore[reportInvalidTypeForm]
def execute(self, context) -> set['OperatorReturnItems']:
node_tree = context.space_data.edit_tree # pyright: ignore[reportAttributeAccessIssue, reportOptionalMemberAccess]
node = node_tree.nodes[self.node_name]
try:
res = node.evaluate(operator=self)
if res == 'ok':
self.report({"INFO"}, f"Execution Successful")
except Exception as e:
self.report({"ERROR"}, f"Execution failed: {str(e)}")
import traceback
traceback.print_exc()
return {"FINISHED"}
@register_class
class SLICENODE_MT_Menu(Menu):
bl_idname = "SLICENODE_MT_Menu"
bl_label = "SliceNodes"
def draw(self, context):
layout = self.layout
assert layout
layout.operator("node.add_node", text="String").type = "SLICENODE_InputString"
layout.operator("node.add_node", text="Float").type = "SLICENODE_InputFloat"
layout.operator("node.add_node", text="Integer").type = "SLICENODE_InputInt"
layout.operator("node.add_node", text="Rotation").type = "SLICENODE_InputVectorRotation"
layout.operator("node.add_node", text="Math").type = "SLICENODE_FloatMath"
layout.operator("node.add_node", text="Integer Math").type = "SLICENODE_IntMath"
layout.operator("node.add_node", text="Object").type = "SLICENODE_InputObject"
layout.operator("node.add_node", text="Printer").type = "SLICENODE_InputPrinter"
layout.operator("node.add_node", text="Printer List").type = "SLICENODE_PrinterList"
layout.operator("node.add_node", text="Printer Intrinsics").type = "SLICENODE_InputIntrinsics"
layout.operator("node.add_node", text="Test").type = "SLICENODE_Test"
layout.operator("node.add_node", text="Get Mesh").type = "SLICENODE_GetMesh"
layout.operator("node.add_node", text="Get Paths").type = "SLICENODE_GetPaths"
layout.separator()
layout.operator("node.add_node", text="Slice Shells").type = "SLICENODE_SliceShells"
layout.operator("node.add_node", text="Buffer Shells").type = "SLICENODE_BufferShells"
layout.operator("node.add_node", text="Buffer Shells Multiple").type = "SLICENODE_BufferShellsMultiple"
layout.operator("node.add_node", text="Infill").type = "SLICENODE_Infill"
layout.operator("node.add_node", text="Paths to Gcode").type = "SLICENODE_PathsToGcode"
layout.separator()
layout.operator("node.add_node", text="Gcode Block").type = "SLICENODE_GcodeBlock"
layout.operator("node.add_node", text="Gcode Helper").type = "SLICENODE_GcodeHelper"
layout.operator("node.add_node", text="Load Gcode").type = "SLICENODE_LoadGcode"
layout.separator()
layout.operator("node.add_node", text="Join Gcode").type = "SLICENODE_JoinGcode"
layout.operator("node.add_node", text="Join Mesh").type = "SLICENODE_JoinMesh"
layout.operator("node.add_node", text="Join Paths").type = "SLICENODE_JoinPaths"
layout.operator("node.add_node", text="Join Execution").type = "SLICENODE_JoinExecution"
layout.operator("node.add_node", text="Boolean Paths").type = "SLICENODE_JoinSlices"
layout.separator()
layout.operator("node.add_node", text="Gcode to File").type = "SLICENODE_GcodeToFile"
layout.operator("node.add_node", text="Gcode to Text Block").type = "SLICENODE_GcodeToTextBlock"
layout.operator("node.add_node", text="Start Print").type = "SLICENODE_StartPrint"
layout.operator("node.add_node", text="Gcode to Mesh").type = "SLICENODE_GcodeToMesh"
layout.operator("node.add_node", text="Executor").type = "SLICENODE_Executor"
def draw_add_menu(self, context):
space = context.space_data
tree = getattr(space, "edit_tree", None)
if tree and tree.bl_idname == "SLICETREE_NodeTree":
self.layout.separator()
self.layout.menu("SLICENODE_MT_Menu")