Getting Started¶
Installation¶
G-code Reader requires Python 3.10+ and Poetry.
git clone https://gitlab.com/composites-maine-edu/advancing-rapid-prototyping/modeling-and-simulation/gcode-reader.git
cd gcode-reader
poetry install
To also install optional extras (matplotlib, Jupyter, plotly):
poetry install --with extras
Basic Usage¶
Parse to a DataFrame¶
The simplest way to extract G-code data is via a Pandas DataFrame:
import gcode_reader as gr
df = gr.gcode_file_to_dataframe("my_part.gcode")
print(df[["x", "y", "z", "time"]].head())
Parse to an Operation Object¶
For machine-aware emulation, use gcode_to_operation:
import gcode_reader as gr
operation = gr.gcode_to_operation("my_part.gcode", machine="cead")
# Iterate over individual commands
for cmd in operation.commands:
print(cmd)
Specify a Machine Type¶
Pass a machine alias to select machine-specific process emulation:
operation = gr.gcode_to_operation("my_part.gcode", machine="cincinnati")
List all supported aliases at runtime:
machines = gr.list_supported_machines()
print(list(machines.keys()))
Use a Machine Class Directly¶
For more control, instantiate a machine class directly:
from gcode_reader.emulate.machines import CEADAMFlexbot
machine = CEADAMFlexbot()
operation = machine.gcode_file_to_operation("my_part.gcode")
Parse an Additive Part¶
For additive manufacturing workflows, parse directly to an AdditivePart:
import gcode_reader as gr
part = gr.gcode_to_additive_part("my_part.gcode", machine="juggerbot")
Reading Individual Lines¶
from gcode_reader import read_gcode_line, read_gcode_file
# Parse a single line
cmd = read_gcode_line("G1 X10.5 Y20.3 F3000")
# Read an entire file into a list of raw lines
lines = read_gcode_file("my_part.gcode")