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