multiple previews

This commit is contained in:
Nicolas Predella 2026-05-27 19:06:49 +03:00
parent 5aad206c48
commit efc3c65982

View file

@ -1345,7 +1345,7 @@ class SLICENODE_PrusaslicerSlice(SliceNode):
def init(self, context): def init(self, context):
self.add_input("SLICESOCK_PrusaslicerConf", "Config") self.add_input("SLICESOCK_PrusaslicerConf", "Config")
self.add_input("SLICESOCK_Settings", "Settings") self.add_input("SLICESOCK_Settings", "Settings")
self.add_multi_socket_group("SLICESOCK_Mesh", "SLICESOCK_GcodeRo", name="Slicing Group") self.add_multi_socket_group("SLICESOCK_Mesh", "SLICESOCK_GcodeRo", name="Slicing Group", in_name="Mesh", out_name="Gcode")
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
assert layout assert layout
@ -1480,15 +1480,15 @@ class SLICENODE_PrusaslicerPreview(ExecSliceNode):
def init(self, context): def init(self, context):
self._init_exec() self._init_exec()
self.add_input("SLICESOCK_Gcode", "Gcode") self.add_multi_socket_group("SLICESOCK_Gcode", name="Gcode")
def draw_buttons(self, context, layout): def draw_buttons(self, context, layout):
super().draw_buttons(context, layout) super().draw_buttons(context, layout)
layout.prop(self, "prusaslicer_executable") layout.prop(self, "prusaslicer_executable")
def evaluate(self, operator=None): def evaluate(self, operator=None):
gcode: str = self.resolve("Gcode") gcodes: list[str] = [g for g in self.resolve_multi_input("Gcode") if g]
if not gcode: if not gcodes:
if operator: operator.report({'ERROR'}, "No Gcode to preview") if operator: operator.report({'ERROR'}, "No Gcode to preview")
return 'no gcode' return 'no gcode'
@ -1514,27 +1514,27 @@ class SLICENODE_PrusaslicerPreview(ExecSliceNode):
if operator: operator.report({'ERROR'}, f"Command or executable not found: {cmd_parts[0]}") if operator: operator.report({'ERROR'}, f"Command or executable not found: {cmd_parts[0]}")
return 'error' return 'error'
# Write to temp file # Write to temp files
# We use a named temporary file that stays around for a bit. # We use named temporary files that stay around for a bit.
# PrusaSlicer needs the file to exist when it starts. # PrusaSlicer needs the files to exist when it starts.
fd, temp_path = tempfile.mkstemp(suffix='.gcode')
try: try:
with os.fdopen(fd, 'w', encoding='utf-8') as f: for gcode in gcodes:
f.write(gcode) fd, temp_path = tempfile.mkstemp(suffix='.gcode')
with os.fdopen(fd, 'w', encoding='utf-8') as f:
f.write(gcode)
cmd = cmd_parts + ["--gcodeviewer", temp_path] cmd = cmd_parts + ["--gcodeviewer", temp_path]
# Use Popen to not block Blender # Use Popen to not block Blender
subprocess.Popen(cmd) subprocess.Popen(cmd)
if operator: if operator:
operator.report({'INFO'}, f"PrusaSlicer Preview launched") operator.report({'INFO'}, f"PrusaSlicer Previews launched")
except Exception as e: except Exception as e:
if operator: operator.report({'ERROR'}, f"Failed to launch preview: {str(e)}") if operator: operator.report({'ERROR'}, f"Failed to launch preview: {str(e)}")
return 'error' return 'error'
return 'ok' return 'ok'
@register_class @register_class
class SLICENODE_GcodeToMesh(ExecSliceNode): class SLICENODE_GcodeToMesh(ExecSliceNode):
bl_label = "Gcode Preview" bl_label = "Gcode Preview"