-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlicer code.py
More file actions
34 lines (27 loc) · 1.25 KB
/
Copy pathSlicer code.py
File metadata and controls
34 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import subprocess
def generate_gcode(stl_file, output_dir, slic3r_script='/home/fav/Slic3r/slic3r.pl'):
"""
Generate G-code from an STL file using the Slic3r Perl script.
Parameters:
stl_file (str): Path to the STL file.
output_dir (str): Directory where the G-code file will be saved.
slic3r_script (str): Path to the Slic3r Perl script.
"""
if not os.path.exists(stl_file):
raise FileNotFoundError(f"STL file '{stl_file}' not found.")
if not os.path.exists(output_dir):
os.makedirs(output_dir)
gcode_file = os.path.join(output_dir, os.path.splitext(os.path.basename(stl_file))[0] + '.gcode')
command = ['perl', slic3r_script, stl_file, '--output', gcode_file]
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"G-code generated successfully: {gcode_file}")
print(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error generating G-code: {e.stderr}")
raise
if __name__ == '__main__':
stl_file_path = '/home/fav/Desktop/Code/DemoTO.stl' #STL file path
output_directory = '/home/fav/Desktop/Code' # Desired output directory
generate_gcode(stl_file_path, output_directory)