Extracting Models from a .gcode.3mf File

People often post claims they haven’t tested. This is one of them. As Reagan said: “Trust but verify.” My standing advice to newcomers: don’t believe anything you haven’t proved yourself. Too much gets repeated as fact without evidence. Screenshots tell the real story, which I’ve included below. All in all, this was a fun exercise and I thank the poster for raising it. I only wish the outcome had been more positive, since that would have been huge. I’ve been chasing this answer for quite some time using open-source software, but this ain’t it. :worried: I welcome others to review my data and please, please if you have an alternate path that you can actually show works, share it with the community.

____________________________________________________

I chased down the claim that you can convert G-Code back into STL. Technically true, but useless in practice. Here’s the breakdown:

  1. Can Prusa Slicer export G-Code into STL?
  • No not exactly. The utility is prusa-gcodeviewer.exe inside the Prusa Slicer folder. Dragging a G-Code file into Prusa Slicer invokes it or you could create a shortcut to your desktop and access it there.

    • Side Note: This search allowed me to discover Blender 4.5 has a better add-on extension which will do this directly and more accurately. I was stuck on v3.7 which didn’t have this feature. (Link to the extension, you need Blender loaded first: https://github.com/kmnunley/Simple-GCode-Importer)
  1. Does Prusa viewer output STL?
  • No. As stated earlier in this thread, it only outputs OBJ. You then have to convert OBJ to STL with another program. That could be any program like Bambu Studio.
  1. Does it recreate the original STL?
  • ■■■■ no. What you get are toolpaths, not the model. Big difference. (See footnotes for evidence.)

The Naked Truth

Test case: a 25mm cube. More complex parts crashed every program. The cube did output to OBJ and imported into Bambu Studio, Meshmixer, Windows 3D Viewer, and Blender. From there I could export to STL, but it’s not what you think.

The STL is not the mesh

It’s just polygons of filament paths. You aren’t recovering the model, you’re dumping extruded layers.

Why it’s worthless

My cube produced 189,544 triangles, 17,952 non-manifold. Repair took 4 hours for a cube. Real models are worse. The files look fine in different viewers, but all you’re seeing is filament spaghetti, not geometry you can reuse.

Conclusion

Interesting rabbit hole, but dead end. Converting G-Code to STL doesn’t recover a model. It outputs toolpaths in mesh form, which is a completely different thing. This is not a solution.


_____________________________________________

Footnotes / Evidence

Prusa G-Code Viewer Output

Repair attempt on simple 25mm cube STL (189,544 triangles / 17,952 non-manifold) Over four hours to complete!!! On a more complex shape, it crashed all of the programs that I tried.


Windows 3D Viewer renderings


Meshmixer view of converted STL

Blender render showing filament geometry

OnShape showing individual parts

If there was a good use case for it then I don’t think it would be that hard to write a blender plugin that takes the gcode and records just the outer vortexes of any objects included (dissolving any vortexes that are all in straight line) and then joins the vortexes up to create a solid shape.

If I could think of a good reasons to do it I might have a go myself - I suppose Timelapse simulations where you only want to show a few layers being printed - maybe a few at the bottom of the print and a few at the top - then it would be much more efficient to have intermediate layers of the objects nice simple 3d shapes - rather 10s of thousands of curves.

In my version of the gcode Addin I do make it a lot more efficient by combining a lot of the individual curves into larger objects - which makes blender perform a lot better.

Or alternatively it might be possible to take in the obj file out of prusaslicer and somehow get blender to simplify the model by applying a few of the modifiers - however I suspect you would end up with a lot of non-manifold issues.

That reminds me of a math professor I had in college. Whenever he said, “It should be intuitively obvious that X = …,” it was usually followed by a one-line equation hiding a ten-page proof far above most students’ heads. Nothing is ever “obvious” or “not that hard” until someone actually does the heavy lifting. Or as one of my manufacturing engineers used to say: “Just because you can draw it in CAD doesn’t mean it can be built.” :wink:

In this case, the use case was already stated at the top of the thread. It comes up so often there are multiple paid solutions in the market, yet reviews show none of them are complete. That alone shows how hard it is. If funded developers haven’t solved it, it’s a hard problem.

While the solution has eluded the community, the issue itself is simple: too many models are uploaded as GCODE only. That creates two problems. First, GCODE is printer-specific, and firmware safety checks don’t guarantee a crash won’t happen. Second, you can’t modify the model. Anyone who’s tried knows this. Load such a file in a slicer and you’re stuck in “Preview” mode. Try it with the attached example: click Preview, accept the dialog, and the model is erased. Why? Because a GCODE file isn’t a mesh - it’s just a list of X,Y,Z moves, not triangles. That’s why no plugin has cracked it - it’s motion, not geometry.

GCode only example

Cube_TPU_33m40s.gcode.3mf (100.5 KB)

Thinking about the logic of the blender addin a bit more - I think it should be possible to filter out just the external wall related gcode moves (g0-g3) and just apply them as vortexes, rather than bezier curves following every move like the addins do, with lines between the vortexes on the same layer.

That will result in a layer by layer mesh of the outline of the shapes,

Not sure what sort of results there would be if a line was added between every point on a layer and the nearest point on the next layer.

Will try this out at some point on a gcode sliced benchy.

Would probably be simpler to translate the G2s and G3s into smaller straight moves - as that would make the layer by layer point joining a bit easier.

Remember that math professor I referenced earlier? This is exactly that problem.

There’s no such thing as a simple geometric transformation in math, or at least it’s not simple to this “country boy” from NYC. :rofl: But if you find one that actually works, I’ll be all over it.

In my never-ending quest for such a tool, service, or license, everything I encountered so far was either a university-level science project with half-baked code that required a specialized Docker or Python setup, or a “just almost” online solution. Bottom line: everything I found was full of compromises, producing results like I showed above or simply not working as advertised.

I was going to post two sites I had previously bookmarked in one of my rabbit-hole journeys on this topic, but one, a 2017 startup, did not survive COVID and shut down in 2022. That tells you there is not enough money in this for a company to make a go at it. The simple truth is the problem is too hard to solve, too infrequently needed, and nobody has figured out a way to reverse the mesh-to-GCODE process. It does not look like there is enough interest to get it solved. :man_shrugging:

Here’s the other site, still online. I tried the free tier, but I will not pay for the upgrade. In my tests, it struggled with even a simple cube, and all their published examples are simplistic models. This did not leaving me with the confidence that my money would be well spent. Give it a try and you’ll see:

https://gcode2l.com/

__________________________________________________

BTW: This is not different than the bigger holy grail I’ve been searching for; flawless STL-to-STEP where I can get the same STEP file that was converted into an STL upon import, converted back to STEP. Sure there are solutions, all half-baked. In my view the real answer here is that Slicers should allow for “Storing” of the STEP file and re-mesh upon slicing. For the life of me, I do not understand why this has never been done. The 3MF file format allows for it.