STL to Gcode

STL files were originally made for 3D printing, as a simple, convenient file format to represent everything from CAD files to scanned 3D objects. Along the way, the format gained enough popularity that it ended up being used for CNC machines as well.

What is an STL file?

An STL file is a file format that represents objects as a collection of tiny triangles. STL files are only useful for manufacturing since you cannot easily edit an STL file.

STL files have the benefit of being able to represent almost anything, including:

  • Precise mechanical parts
  • Freeform organic shapes
  • Scanned objects
  • Sculpted objects

They are ideal for CNC machining.

STL to Gcode for 3D Printers

The G-code used for CNC machines is completely different than the G-code used for 3D printers. In most cases, your 3D printer will come with a “slicer” program that will convert your STL file to G-code. The slicer program will take into account the type of filament, and the type of printer (FDM, SLA, etc) to create the G-code. Most slicers are based on one of the following two programs:

These slicers will not do anything useful for CNC machines, so you’ll need to use a different program for that.

The STL to G-code Conversion Process for CNC

The G-code conversion process requires the use of a CAM (Computer Aided Manufacturing) program, in our case, MeshCAM CNC Software. Because of the large file size of an STL, not all CAM programs can import them. MeshCAM is capable of loading even very large STL files and quickly creating a toolpath.

The CAM software will load the STL file, and create a toolpath for your CNC machine to follow, based on the cutter shape you’ve defined. There’s a massive amount of math involved, but modern computers can do the calculations very quickly.

How to Convert STL files to G-code

  1. Get a trial of MeshCAM. It will be fully functional for 14 days so you can run real jobs before you spend any money.
  2. Run MeshCAM and Select your Machine
  3. Go to File->Open and select your STL file
  4. Go to CAM->Toolpath and select Unified Finishing
  5. Click “Calculate Toolpaths” to see what the path of your cutter will be.

Questions about STL Files

Where can I get STL files?

STL files can be exported from almost any CAD program. If you don’t have a CAD file already, you can buy pre-made STL files from places like Etsy for a couple of dollars each.

How accurate are STL files?

People worry about STL accuracy, but STL files can be more accurate than your CNC machine by far. (Especially if your machine cost less than $100k) The downside is that the more accuracy you need, the more triangles are put into the file, and the larger the file gets.

Do the STL files need to be watertight for CNC?

“Watertight”, in the context of an STL file, means that the shape has no holes in it. The file represents a complete shell of a 3D solid.

For 3D printing, STL files need to be watertight for the slicer to work properly. For a CNC mill, the files do not need to be watertight. You can have gaps and tiny holes in your file and the CAM software will still be able to create a good toolpath.