Перейти до основного вмісту

raygeo.gcode

G-code (RS274/NGC) geometry extraction.

Parses the common subset of RS274/NGC used by laser cutters, CAM tools and LightBurn into Geometry objects. Only material-removing moves are emitted: rapid moves, and feed moves at spindle speed zero, split the result into separate contours.

GcodeParseResult​

The cutting geometry and skipped instructions of one G-code program.

geometry​

geometry: geo.Geometry

Cutting moves in millimetres, Y-up, one subpath per contour.

unsupported​

unsupported: list[str]

Instructions that were recognized but not applied, sorted.

Functions​

parse_gcode()​

parse_gcode(text: str, s0_is_travel: bool = True) -> gcode.GcodeParseResult

Parse a G-code program into cutting geometry in millimetres.

Supports G0 (rapid), G1 (linear cut) and G2/G3 (arcs in I/J or R form), with G20/G21 units, G90/G91 distance mode and G90.1/G91.1 arc-centre mode. Comments, block delete, % delimiters and CRLF line endings are handled. Feed, spindle speed, coolant and work offsets do not affect the geometry.

ParameterTypeDescription
textstrThe G-code program as text.
s0_is_travelbool = TrueTreat feed moves at spindle speed zero as travel (LightBurn fill passes and overscan).
Returnsgcode.GcodeParseResultCutting geometry in millimetres plus the sorted set of instructions that were skipped.
ComplexityO(n) where n = size of the program