-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbenchy.py
More file actions
85 lines (70 loc) · 3.06 KB
/
benchy.py
File metadata and controls
85 lines (70 loc) · 3.06 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""Simulating the G-code of a 3DBenchy from PrusaSlicer on a Prusa MINI."""
import importlib.resources
import pathlib
from pyGCodeDecode.abaqus_file_generator import generate_abaqus_event_series
from pyGCodeDecode.gcode_interpreter import setup, simulation
from pyGCodeDecode.helpers import custom_print
from pyGCodeDecode.plotter import plot_3d
from pyGCodeDecode.tools import save_layer_metrics
def benchy_example():
"""Extensive example for the usage of pyGCodeDecode simulating G-code for the famous 3DBenchy."""
# setting the paths to the input and output directories
data_dir = importlib.resources.files("pyGCodeDecode").joinpath("examples/data/")
output_dir = pathlib.Path.cwd() / "output_benchy_example"
custom_print(
"Running pyGCD's benchy example! 🛥️"
"\nThis example illustrates an extensive use of the package: \nA gcode is simulated with default presets from a "
"file provided alongside this example. After the simulation, an interactive 3D-plot is shown."
"\nThe following files are saved to a new folder in your current directory: ",
output_dir.__str__() + " 💾",
"\n - a screenshot of the 3D-plot 📸"
"\n - a .vtk of the mesh 🕸️"
"\n - a summary of the simulation 📝"
"\n - some metrics for each layer 📊"
"\n - an event series to use with ABAQUS. 📄",
)
# setting up the printer
printer_setup = setup(
presets_file=data_dir / "printer_presets.yaml",
printer="prusa_mini",
layer_cue="LAYER_CHANGE",
)
# set the start position of the extruder
printer_setup.set_initial_position(
initial_position={"X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0},
input_unit_system="SI (mm)",
)
# running the simulation by creating a simulation object
benchy_simulation = simulation(
gcode_path=data_dir / "benchy.gcode",
initial_machine_setup=printer_setup,
output_unit_system="SI (mm)",
)
# save a short summary of the simulation
benchy_simulation.save_summary(filepath=output_dir / "benchy_summary.yaml")
# print a file containing some metrics for each layer
save_layer_metrics(
simulation=benchy_simulation,
filepath=output_dir / "benchy_layer_metrics.csv",
locale="en_US.utf8",
delimiter=",",
)
# create an event series to use as input for an ABAQUS-simulation
generate_abaqus_event_series(
simulation=benchy_simulation,
filepath=output_dir / "benchy_prusa_mini_event_series.csv",
tolerance=1.0e-12,
output_unit_system="SI (mm)",
)
# create a 3D-plot and save a VTK as well as a screenshot
benchy_mesh = plot_3d(
benchy_simulation,
extrusion_only=True,
screenshot_path=output_dir / "benchy.png",
vtk_path=output_dir / "benchy.vtk",
)
# create an interactive 3D-plot
# the mesh from the previous run can be used to avoid generating a mesh again
plot_3d(benchy_simulation, mesh=benchy_mesh)
if __name__ == "__main__":
benchy_example()