gcode_reader.emulate.exporters¶
Classes¶
Translates abstract Command objects into G-code strings or data series. |
|
Exports geometry and scalar data to PyVista and VTK formats. |
Module Contents¶
- class gcode_reader.emulate.exporters.GcodeExporter(syntax_name='default')[source]¶
Translates abstract Command objects into G-code strings or data series.
This class uses configurable “syntax flavors” to handle different G-code dialects. It can export a sequence of Command objects into a final G-code file or into a format suitable for data analysis (e.g., a Pandas DataFrame).
Initializes the GcodeExporter with a specific syntax flavor.
- Parameters:
syntax_name (str, optional) – The name of the syntax flavor to use, which corresponds to a definition in gcode_reader.syntax.flavors. Defaults to “default”.
- command_to_dict(command: gcode_reader.emulate.commands.Command) dict[source]¶
Converts a Command instance into a plain dict suitable for a DataFrame row.
Prefer this over command_to_pd_series when building a DataFrame from many commands — passing a list of dicts to pd.DataFrame() is significantly faster than passing a list of pd.Series.
- Parameters:
command (Command) – The Command object to convert.
- Returns:
A dictionary containing the command’s G-code words and metadata.
- Return type:
- command_to_gcode_line(command: gcode_reader.emulate.commands.Command) str[source]¶
Constructs a complete G-code line string from a Command object.
This method orchestrates the G-code generation process. It first converts the command to a dictionary of words, then uses the list of gcode_line_helpers to assemble those words into a final, space- delimited G-code string.
- command_to_gcode_words(command: gcode_reader.emulate.commands.Command) dict[source]¶
Converts a Command’s data into a dictionary of G-code words.
This method uses the exporter’s word_map to translate the Command’s internal attributes (e.g., position) into the corresponding G-code words and values (e.g., {‘X’: 10, ‘Y’: 20}). It’s the first step in converting a command to either a string or a data series.
- command_to_pd_series(command: gcode_reader.emulate.commands.Command)[source]¶
Converts a Command instance into a pd.Series.
For bulk DataFrame construction use command_to_dict instead.
- property code_map¶
- gcode_line_helpers¶
- property syntax¶
- property word_map¶
- write_order = ('G', 'M', 'X', 'Y', 'Z', 'A', 'B', 'C', 'F', 'E')¶
- class gcode_reader.emulate.exporters.VTKExporter[source]¶
Exports geometry and scalar data to PyVista and VTK formats.
- static additive_part_to_polydata(additive_part: gcode_reader.emulate.additive_part.AdditivePart, deposition_range: tuple = None, custom_scalars: dict = None) pyvista.PolyData[source]¶
Converts an AdditivePart to a PyVista PolyData mesh with scalar fields.
- Parameters:
additive_part (AdditivePart) – The part to convert.
deposition_range (tuple, optional) –
(start, end)pair of 0-based indices into the ordered sequence of depositing segments, selecting a contiguous subset to mesh.Noneincludes all depositing segments.custom_scalars (dict, optional) – Mapping of
{name: array}for additional or replacement scalar arrays stored as cell data. Use this to supply measured data (e.g. temperature) or any other derived field. Array length must equalmesh.n_cells(one value per line-segment).
- Returns:
Mesh with scalar arrays in
cell_data.- Return type:
pv.PolyData
- Raises:
TypeError – If
additive_partis not anAdditivePart.ImportError – If pyvista is not installed.
- static additive_part_to_vtk(additive_part: gcode_reader.emulate.additive_part.AdditivePart, filepath: str, binary: bool = True, deposition_range: tuple = None)[source]¶
Exports an AdditivePart to a
.vtkfile with embedded scalar fields.- Parameters:
additive_part (AdditivePart) – The part to export.
filepath (str) – Destination path; must end with
.vtk.binary (bool, optional) – Write binary VTK format. Defaults to True.
deposition_range (tuple, optional) –
(start, end)pair of 0-based indices into the ordered sequence of depositing segments to export.Noneexports all depositing segments.
- Raises:
TypeError – If
additive_partis not anAdditivePart.ValueError – If
filepathdoes not end with.vtk.FileNotFoundError – If the parent directory of
filepathdoes not exist.