Does anyone know if there's a way to convert G-code back into a model

Does anyone know if there’s a way to convert G-code back into a model for FEM/FEA? We are trying to analyse the strength of a simulated print in Pro-E.

I hope there’s a good answer for this question, I’ve thought it myself, when I could get a hold of G-code instead of an STL or OBJ.

I’m not sure about the FEM/FEA part, but there is a thread about g-code to STL:

@Fred_U , We tried that “reverser” but it only outputs a mesh shell, the structure of the infill is lost.

Short answer, no, it doesn’t exist. It’s a bit of a “holy grail” technology for additive manufacturing.

The complexity is enormous. Polymer behavior is already complicated (eg creep and strain crystallization effects), and local extruded strand properties add a whole new dimension. We’re talking non-homogeneous and anisotropic properties WITHIN the strand (depending on local print speed and thermal fluxes and strand aspect ratios and even recent shear history due to transients like retractions) as well as anisotropic properties at the macro scale due to strand alignment, grain structure, and void space effects. AND EVEN IF you captured all that, the resulting FEA output likely wouldn’t be very accurate anyway, due to printer calibration/configuration variations.

Empirical testing is the correct answer.

G-code is hot end movements with extrusion and speed values. It can’t be turned back because too much data has been lost. You could read the path lines from the g-code and try to reconstruct from it but there is a lot of slicer data that would need to be recovered and feed to the software tool to get anything close. Imagine a software tool trying to figure out where support structure and part separate. For that matter how would software know which was which.

I did a quick search for “convert mesh to stl” and found a number of options, but of course that increases the workload involved. One of the suggestions includes using SolidWorks to import the mesh, which then opens up a number of choices and operations. Not the lowest price option on the mat, either, although there is a free trial if you jump through their hoops.

Is this a one time, an occasional, or a frequent process you’ll be attempting?

I’m not sure if this is what you need, but there is a Blender addon that allows you to import gcode, turning the extrude moves into mesh (or curve data displayed as tubes, I don’t remember, it’s been years since I’ve used it. Curves can be converted to mesh anyway).
The latest version seems to be here:

You can see what its output looks like here (older version):

@Fred_U , our engineering staff wants to be able to print test jigs/fixtures. Since it is a functional part our policy requires FEA to be done for the final design review.

@Ryan_Carlyle , I just found an old Blender add-on to do the conversion, but it appears to be somewhat broken. I’m hoping that it will work with a little debugging. …I do agree with you about this being hopelessly complex/inaccurate but the boss wants “engineering data”, lol!

@Matthew_Satterlee Check my response above for a more recent version of the addon

@Matthew_Satterlee Hah, ok, if you’re just checking a box, then go right ahead and let us know how you do it :slight_smile:

What I might recommend as an alternative to reconstructing the gcode is to model the part as a hollow shell based on the perimeter/roof/floor thickness (ignore infill) and hand-wave that it’s a conservative approximation. For most real-world loads, the shell is taking the majority of the stress anyway. (EG bending stress concentrates on the exterior of the part.)

@kongorilla, thank you! … It looks like I was typing when you posted that.

EDIT: This is really cool work! It probably won’t be what the boss was hoping for but I’ll certainly be using it at home. :smiley:

@Ryan_Carlyle , I’m considering putting some of the parts on a desk and beating them with a hammer to show everyone they are sufficiently resilient. :wink: … Most likely I will tell the boss there is no viable FEA solution and he will waive the requirement, but I had to give it the ol’ college try. C’est la vie!

@Matthew_Satterlee I’ll back Ryan up on this one: Trying to FEA the parts based on the toolpaths is a fools errand.

You probably can set up an anisotropic material to do a rough approximation in FEA though.

If you’re printing above 30% infill or so the ultimate failure stresses for printed parts are predictable to around +/- 20%, and short of failure I don’t think printed stuff has an elastic modulus significantly different from their parent polymer in bulk. Punch those values in and keep your safety factors up at like 5 and I think you could do meaningful FEA on fixtures.

*This is based on data from my research last year, but you’ll want to throw your own printer’s output in a machine to get your values.

You could write a script in Python to get Blender to re-create the g-code, I suppose. Using Bezier curves or paths, you would re-create every move, and then “fatten” the paths and convert the whole caboodle to a mesh. Might not be exactly what you want, but if I understood you correctly it would get pretty close.

Sounds like an interesting challenge. If I have a moment I might give it whirl myself.

Should have read to the end of the comments :slight_smile: Oh well, at least it looks like I was thinking in the right direction.

Your Fea will not be that accurate. The squishing and fusing of layers wouldn’t be accounted for. the best approximation would be modeling the infill for one layer and extruding it. My method of doing that would be to print the object, scan the object (using a paper scanner), trace the outline of the infill pattern in inkscape, export the pattern as dxf, load the dxf in CAD, extrude the solid and don’t put tensile force normal to the layer lines.

If you want to analyse layer adhesion, there is no model for layer to later bonding force that I am aware of. This is highly dependent on the print settings.