Preview gcode in OpenSCAD

I made a little Python script that takes a gcode file from Estlcam (or maybe other sources – but currently not that many gcode features are supported, so YMMV) and generates an OpenSCAD file which simulates the cut with an adjustable bit shape (you can adjust the bit tip angle, the diameter and the length). The cut gets subtracted from a solid representing the workpiece (by default a 1000x1000x6mm “cube”, but can be adjusted).

This should work better for some purposes than Repetier Host or Estlcam preview.

To run:

python filename.gcode > filename.scad

OpenSCAD rendering is slow because of the subtraction, and Render may work better than Preview. (You can also not subtract by setting workWidth=0, which will increase speed.)

[attachment file=103335]


Very nice. I can’t wait to try it.

WHat!!?!?! If this works That would be awesome!

Very cool!

You also may try to adapt your script to


Because openscad is really slow. Honestly, i didn’t try new openscad 2019.05, but I’m sceptical about it will be much faster.

ImplicitCAD lacks the convex hull operation, so it won’t work. I also tried OpenJSCAD, but it only supports 2D convex hulls. I could write the code to generate a polyhedron representing a cutting bit path between two points directly rather than by just doing a convex hull of two cutting bit shapes, but I am not sure how well it’ll work.

IceSL is worth trying, but it will be complicated.

I agree that OpenSCAD is slow. But it’s still probably a bit faster than wasting a piece of wood on a cut that doesn’t do what one wants. The mekleth render in my screenshot takes just under 8 minutes (using Render mode; Preview mode doesn’t work well with giant subtractions). That’s because subtracting the cutting path from the solid is an enormously expensive operation.

If one wants to see just the solid cutting path (by setting workWidth to 0), one can use Preview mode and it takes 4 seconds. Here’s the cutting path render.


I tried OpenJSCAD and ImplicitCAD again with a pre-rendered cutting path, just testing the subtraction speed, and it was way slower than OpenSCAD (in fact, I let them run for about 20 minutes and gave up).

Icesl somehow tries to use opengl for accelerations, so may be it can be faster. Honestly, i guess it could even parse gcode file by itself, because it’s pure Lua.

By the way, best solution imho, if Cristian will implement it as a feature of estlcam.

I’m use fusion 360 and cam simulation subsystem of it is great.

Freecad cam also has internal feature to produce cutted shape.

Regardless of the speed, functionality comes first. Building this on such a freely available tool as openscad is a huge feature.

IceSL renders pretty fast (in a second or two), but unfortunatelly only up to 900 segments. with more segments it crashes.

[attachment file=103541]

I just optimized the script for the most common use case for me: a flat-bottomed bit with most of the cuts horizontal, so I can compute the cuts at each fixed z-height with a 2D rather than 3D hull() operation and just extrude them vertically. The code reverts to the old, slower method if you have a sharp bit.