multiple previews
This commit is contained in:
parent
5aad206c48
commit
efc3c65982
1 changed files with 19 additions and 19 deletions
|
|
@ -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'
|
||||||
|
|
||||||
|
|
@ -1508,33 +1508,33 @@ class SLICENODE_PrusaslicerPreview(ExecSliceNode):
|
||||||
abs_path = bpy.path.abspath(cmd_parts[0])
|
abs_path = bpy.path.abspath(cmd_parts[0])
|
||||||
if os.path.exists(abs_path):
|
if os.path.exists(abs_path):
|
||||||
cmd_parts[0] = abs_path
|
cmd_parts[0] = abs_path
|
||||||
|
|
||||||
# Final check if command exists
|
# Final check if command exists
|
||||||
if not shutil.which(cmd_parts[0]):
|
if not shutil.which(cmd_parts[0]):
|
||||||
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:
|
||||||
cmd = cmd_parts + ["--gcodeviewer", temp_path]
|
f.write(gcode)
|
||||||
|
|
||||||
# Use Popen to not block Blender
|
cmd = cmd_parts + ["--gcodeviewer", temp_path]
|
||||||
subprocess.Popen(cmd)
|
|
||||||
|
# Use Popen to not block Blender
|
||||||
|
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"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue