G-code to STL: what you get back, and when to ask for the source file
By Sina Esfahani, OmniTechs · Published 30 November 2026
Yes, you can turn G-code back into a 3D model, but you will not get the original model. G-code holds no shape. It is the list of moves the printer makes: layer by layer, the paths along which the nozzle lays down plastic. A program can draw a small tube around each path and build a mesh from those. The result looks like the part as it was printed, with steps on sloped faces, ridges on the walls, and the brim, supports and infill included.
So ask for the source file (STL, 3MF or STEP) first, from whoever designed or sliced the part. If that fails, open the G-code in a text editor and look up the layer height and line width. Those two numbers decide how good the rebuild can be.
Work through it in this order:
Ask the designer, the seller or whoever made the G-code for the STL, 3MF or STEP file.
Only want to print the same part again on the same printer with the same filament? Print the G-code again; you do not need an STL.
Read from the G-code which slicer wrote it, the layer height, the outer wall line width and any compensation values.
Open the G-code in PrusaSlicer's free G-code viewer and choose File > Export Toolpaths as OBJ...
Remove the brim, skirt, supports and purge lines, and turn the result into an STL.
Measure the outside dimensions on the crests of the ridges, the holes and the height, and compare them with the real part.
Use the result as a reference for remodelling. Print it directly only when the size is not critical.
Why G-code only approximates the model
How a model turns into G-code in the slicer is explained in how 3D printing works. For working backwards, four steps in that chain matter, and each throws information away.
The slicer takes each layer at half height. By default, Cura and PrusaSlicer take the model's cross-section halfway up each layer. Whatever the model does within a 0.2 mm layer is gone. A sloped face becomes a staircase, and every height lands on a whole layer.
The outer wall sits half a line width inside. The slicer places the centre of the outermost line half a line width inside the model's edge. With a 0.45 mm line, that is 0.225 mm. A rebuild only keeps the size if the program adds that width back, so it has to know the right width.
Corrections are baked in. If elephant's foot compensation or XY compensation was on, the first layer or the whole outline has already been made smaller or larger. The G-code holds the corrected paths, not the design size.
Everything that gets printed comes along. Infill, supports, brim, skirt, purge line and a wipe tower are paths too. The design itself, such as a 6 mm hole with a dimension or a fillet as a feature, never existed in the G-code.
The last point is the same limit you meet when converting an STL to STEP: conversion does not recover the original CAD. Going from G-code to STL leaves you one step further from the design.
What you get back, compared with the original model
| Feature | In the original model | In a mesh from G-code | What to do |
|---|---|---|---|
| Height | Any value | Rounded to whole layers | Measure the real part or ask for the drawing |
| Sloped and curved faces | Smooth | Steps of one layer height | Remodel if the face has to fit |
| Outer wall | Flat face | Ridges; size only right with the correct line width | Measure on the crests of the ridges |
| First layer | Same size as the rest | Smaller with elephant's foot compensation | Ignore the first layer when measuring |
| Inside | Solid or hollow | Infill and inner walls as separate tubes | Skip on import or delete afterwards |
| Supports, brim, purge line | Do not exist | Included in the mesh | Remove by hand |
| Design dimensions and features | Editable in CAD | Not present | Remodel in CAD |
Getting the layer height, line width and compensation from the G-code
G-code is plain text. Open the file in a text editor and search for a few words. The commands you will meet and what they do are covered in G-code commands you will edit.
PrusaSlicer writes all its settings at the end, after the line prusaslicer_config = begin. Search for layer_height, external_perimeter_extrusion_width, elefant_foot_compensation and xy_size_compensation.
Bambu Studio writes its settings at the top, after CONFIG_BLOCK_START. Search for layer_height, outer_wall_line_width, elefant_foot_compensation, xy_contour_compensation and xy_hole_compensation.
Cura writes the layer height near the top, in the line ;Layer height: for printers with Marlin-style G-code. For each kind of path it adds a line such as ;TYPE:WALL-OUTER for the outer wall.
If external_perimeter_extrusion_width is 0, PrusaSlicer uses the general extrusion width, and if that is 0 too, 1.125 × the nozzle diameter: 0.45 mm for a 0.4 mm nozzle. A percentage is worked out over the layer height.
Have a .gcode.3mf from a Bambu Lab printer? That is a ZIP archive. The G-code sits inside as Metadata/plate_1.gcode, and according to the Bambu Studio 02.09.02.62 source code, this type of file leaves out the model itself. The project file (.3mf) kept by the designer or saved when slicing does contain the model.
Which programs build a mesh from G-code
Programs that turn G-code into a mesh, as their makers document them
| Program | What you get | Watch out for | Status on 30 November 2026 |
|---|---|---|---|
| PrusaSlicer and its G-code viewer | OBJ with each path as a tube with a diamond-shaped cross-section | Width from PrusaSlicer's own G-code, otherwise estimated from the extrusion | Version 2.9.7, free |
| Simple Gcode Importer for Blender | Bézier curves with a bead profile, to convert to a mesh | Can skip infill, supports and towers; G-code from Bambu Studio may fail | Version 2.1.2, Blender 4.2 and newer, free |
| GCode2STL | STL or PLY with each path as a square tube | Fixed width (default 0.4 mm); absolute extrusion and G0/G1 only | Source code from April 2024; compile it yourself |
| ZMorph Voxelizer | Not described by the manufacturer | ZMorph now offers Voxelizer for Fab for its own machines | Voxelizer 2.0 servers are off |
Older guides also name the online converters MakePrintable and GCode2L. On 30 November 2026 MakePrintable's address shows only blog posts and gcode2l.com returns an error page (404). Neither converts G-code any more.
PrusaSlicer is the best start for most people. According to Prusa, its standalone G-code viewer opens G-code from PrusaSlicer, Slic3r, Cura, ideaMaker, Simplify3D, Craftware and KISSSlicer. For G-code from another slicer, the viewer estimates line widths, layer heights and path types itself, and may mark some parts as unknown. Bambu Studio and OrcaSlicer are not on that list: try it, and check the result with the measurements below.
GCode2STL is a small command-line program without a ready-made download. Its source code counts a move as extrusion when the E value rises above the highest so far. That works with absolute extrusion (M82), Cura's default, but not with relative extrusion (M83), which Prusa's printer profiles use. It skips arcs (G2 and G3): if your slicer wrote arcs, those parts of the path are missing from the mesh.
Step by step: from G-code to STL with PrusaSlicer and Blender
Menu names are from PrusaSlicer 2.9.7 and the Blender 5.3 manual.
Open the G-code. In PrusaSlicer, choose File > G-code Preview... and pick your file. The standalone G-code viewer opens. In it, you open later files with File > Open G-code...
See what is in it. The legend shows which colour belongs to which kind of path: outer wall, infill, support, skirt or brim. The two handles of the vertical slider limit the layers; according to Prusa, the export contains only the visible layers. Keep all layers visible if you want the whole part.
Export. Choose File > Export Toolpaths as OBJ... You get an OBJ file and an MTL file with colours. Expect a large file: Prusa mentions several million polygons per model.
Import into Blender. Choose File > Import > Wavefront (.obj). G-code is in millimetres, so a 40 mm part shows up as 40 m in a default scene. How to set that right on export is in convert OBJ, GLB or SketchUp to STL.
Clean up. In Edit Mode, delete what does not belong to the part: supports, a brim or a wipe tower. In the PrusaSlicer 2.9.7 source code, the export only drops the layers you hide with the slider. Path types you switch off in the legend, such as infill, are exported anyway.
Make it one closed volume (optional). The OBJ consists of thousands of separate, overlapping tubes. The Remesh modifier in Voxel mode builds a new, closed mesh from them, according to the manual. Choose a voxel size well below the layer height, in your scene's unit: if your 40 mm part shows as 40 m, choose 0.05 m. Smaller voxels give more detail and a heavier file.
Export as STL and open it in your slicer to check the dimensions.
If you would rather stay in Blender, the Simple Gcode Importer extension imports G-code through File > Import. It can skip infill, supports and wipe towers, so you keep only the walls. Convert the curves afterwards with Object > Convert > Mesh. The extension itself warns that G-code from Bambu Studio sometimes imports incorrectly.
How good is it? A worked example
A hypothetical bracket of 40 × 20 × 12 mm with a 6.0 mm hole, a 45° chamfer and a top face that slopes at 15°. It was sliced with a 0.4 mm nozzle, 0.2 mm layers, a 0.45 mm outer wall and 0.2 mm elephant's foot compensation. You only have the G-code.
Height. 12 ÷ 0.2 = 60 layers, so 12.0 mm. Had the model been 12.1 mm tall, the slicer would have made 60 or 61 layers: 12.0 or 12.2 mm. The G-code does not tell you which size was meant.
Outside size. The centres of the outer walls are 40 − 0.45 = 39.55 mm apart. PrusaSlicer adds the width back: 39.55 + 0.45 = 40.00 mm on the crests. Between two layers its diamond cross-section narrows back to the centre, so there you measure 39.55 mm. Measure on the crests of the ridges.
With the wrong width. GCode2STL uses 0.4 mm by default: 39.55 + 0.4 = 39.95 mm, 0.05 mm too small. Give it 0.45 mm and the size is right again.
Hole. The centre of the wall around the hole has a diameter of 6.0 + 0.45 = 6.45 mm. With the right width the hole becomes 6.45 − 0.45 = 6.00 mm; with 0.4 mm it becomes 6.05 mm.
First layer. It has been moved 0.2 mm inwards on each side: 40 − 2 × 0.2 = 39.6 mm wide. Do not measure there.
Sloped faces. Each step is layer height ÷ tan(angle) wide. On the 45° chamfer: 0.2 ÷ 1 = 0.2 mm, and the edge of a step sits up to 0.1 mm off the original face horizontally. On the 15° top face: 0.2 ÷ 0.268 = 0.75 mm per step, up to 0.37 mm off horizontally. Measured square to the face, the error is never more than half a layer: 0.07 mm at 45° and 0.1 mm at 15°.
Straight dimensions therefore come back to within a few hundredths of a millimetre, provided the width is right. On sloped faces, especially shallow ones, an edge can shift horizontally by up to a few tenths of a millimetre. Whether the hole was meant to be 6.0 mm or deliberately larger, nothing tells you. Remodel the bracket with these sizes as a starting point, and check them against the real part.
The contrasting case: the same bracket from Cura, with absolute extrusion, run through GCode2STL with the default width. You get 39.95 mm and a 6.05 mm hole, with the brim and supports included. And if you only want to print the bracket again on the same printer, skip all of this and print the G-code again.
When to ask for the source file instead
A mesh from G-code is enough for a render, to see how something is built, or as a reference for remodelling. Ask for the source file when:
the part has to fit onto something;
you want to change a dimension;
you want to print it on another printer, with another nozzle or in another material;
sloped or curved faces are visible or have to mate.
Ask whoever designed the model, the seller of the file, or whoever made the G-code for you. If you sliced it yourself, check your slicer's recent projects. With a Bambu Lab printer you need the project file, not the .gcode.3mf.
Copyright. If the G-code comes from someone else, the design still belongs to them. In the UK, copyright protection is automatic, with no application or fee; in the Netherlands, too, it arises as soon as the work is made. A mesh you rebuild from the G-code is still that design. If it carries a Creative Commons licence with NoDerivatives (ND), you may not share a modified version; with NonCommercial (NC), you may not use it commercially. When in doubt, ask the designer for permission. This is general information, not legal advice.
Stop rebuilding when the sizes are still outside your tolerance with the right line width, when the part has to fit or carry load, or when the G-code has no path-type comments and you cannot separate infill from walls. Measure the real part and remodel it instead.
Further reading and next step
Starting from an OBJ made in another program? See convert OBJ, GLB or SketchUp to STL. To understand why even a clean STL does not give you an editable CAD file, read STL to STEP does not recover the original CAD.
If the part has to be remodelled, OmniTechs offers a 3D modelling service that works from a sketch, photo, dimensions or the old part. You receive a printable model as STL and STEP. Modelling is its own line in the estimate, and the first assessment is free.
Sources
PrusaSlicer 2.9.7 source: toolpath OBJ export (GCodeViewer.cpp)
PrusaSlicer 2.9.7 source: line width and layer height from G-code (GCodeProcessor.cpp)
PrusaSlicer 2.9.7 source: outer wall (PerimeterGenerator.cpp)
PrusaSlicer 2.9.7 source: cross-section at half layer height (PrintObjectSlice.cpp)
UltiMaker Cura 5.14.0: setting definitions (Slicing Tolerance)
Bambu Studio 02.09.02.62 source: settings in the G-code (GCode.cpp)

