gcode2mesh
Reconstruct a 3D mesh — STL, OBJ, GLB, PLY — from G-code toolpaths.
G-code is a list of machine movements, not a geometry format. There is no model inside the file to extract, so the shape has to be inferred from where the machine was told to go. That makes this a reconstruction, not a conversion: the output approximates the printed or machined part, and it will not match the model the slicer started from.
pip install gcode2mesh # tube reconstruction
pip install "gcode2mesh[voxel]" # solid reconstruction (recommended)
gcode2mesh benchy.gcode benchy.stl
gcode2mesh pocket.nc pocket.glb --radius 0.5
from gcode2mesh import convert, parse_paths, paths_to_mesh
convert("benchy.gcode", "benchy.stl", radius=0.2)
# or work with the geometry directly
paths = parse_paths("benchy.gcode") # list of [x, y, z] polylines
mesh = paths_to_mesh(paths) # a trimesh.Trimesh
Two dialects, detected automatically
Nothing in a G-code file declares which kind it is, so gcode2mesh sniffs for a
real E word before deciding how to read it.
| How material is identified | What you get | |
|---|---|---|
| FDM / 3D printing | moves where the E axis advances |
the printed object, travel moves discarded |
| CNC / subtractive | every non-rapid move | a visualisation of the cutting path |
Getting this wrong is not subtle. Treat a CNC file as FDM and every move looks
like a travel move, leaving nothing at all; treat an FDM file as CNC and the
model comes out webbed together by lines that were never printed. Detection
deliberately requires E to be followed by a number on a non-comment line —
CNC headers contain comments like ;ModelNumber= and ;ActualInstep=, and a
bare letter match on those produced empty output.
How the mesh is built
With scipy and scikit-image installed (the voxel extra), paths are
rasterised into a grid, a distance transform measures the distance to the
nearest deposited point, and marching cubes takes the surface at radius.
Overlapping beads fuse into a single shell, which is what a printed part looks
like.
Without them, each segment is swept into its own tube and the tubes are
concatenated. It works with trimesh alone, but beads do not merge — expect a
bundle of touching tubes rather than a solid.
--radius is half the deposited bead width in the file's own units, usually mm.
The default of 0.2 suits a 0.4 mm nozzle. Raise it for CNC files, where the
tool is much wider than a nozzle.
Limitations
- Arc moves (
G2/G3) are treated as straight segments between endpoints. - Multi-material and multi-extruder files are flattened into one mesh.
- Relative extrusion (
M83) is not tracked; absoluteEis assumed. - The tube fallback keeps only the 2000 longest paths on very large files.
License
MIT.
Built by MiConvert, which runs the same reconstruction in the browser if you would rather not install anything — G-code to STL · G-code to 3MF
Metadata
Release files for gcode2mesh 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| gcode2mesh-0.1.0.tar.gz | 10.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gcode2mesh-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.0 kB
Release files / gcode2mesh-0.1.0.tar.gz
| Download URL | gcode2mesh-0.1.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f4e73c35e4d7448c29a2793ef6a4917bd2ecda040cc875bc911fbeb3d025dba
|
|
BLAKE2b-256 checksum How to use checksums |
4f2eb18cd689252ef25e47757ae9f99b1a0c41ab252582a93501a5f6d0590118
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|
Release files / gcode2mesh-0.1.0-py3-none-any.whl
| Download URL | gcode2mesh-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9cee87d226e92233cf709e233ba06427e45f98484b001a6d3e202473653a3a95
|
|
BLAKE2b-256 checksum How to use checksums |
e9bea2ca2dbd89bea14290afc5e486ea253eb8207f7f048bf9fe603791474270
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|
Security for gcode2mesh 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.