I wrote a tool that can read GCode and create a 3D OpenSCAD model of the resulting object you get after machining is finished. You can find it here on Github: pvdbrand/cnc-3d-gcode-viewer.

There’s an example of a hook I designed and used with EstlCam to generate the gcode:

You can see details like the inside corners, the holding tabs, how far into negative X and Y you are milling, etc.

The preview function in EstlCam and various online gcode viewers only show you a line for the toolpath. While useful, I always find it hard to see what the actual result will look like. Also, you can export the 3D model to STL and use your favorite CAD program to verify dimensions if you want.

## How it works

Basically, the script reads all movement commands from a gcode file (including arcs, which are interpolated to line segments). The script takes the convex hull of the tool model at the start of a movement and at the end position of a movement. Then it takes the union of all movements. This gives you the shape of all the material that has been *removed*. So the final step is to take the stock model and subtract the removed material from it, leaving you with a model of the material that is left over after milling.

The model of the end mill is currently just a cylinder with a configurable diameter, and the model of the stock is just a box with configurable dimensions. It’s quite easy to model anything you want though.