How to Convert STL Files to G-code

Photo of author

Written by Marcello De Lio

Last Updated

4 min read
Close up of a hand holding an SD card with an out of focus Ender 3 V3 SE 3d printer in the background
KEY TAKEAWAYS
  • You can convert STL files to G-code files using free slicing software.
  • The slicer allows you to adjust print settings and create G-code for 3D printing.
  • Transfer the G-code to your printer to begin printing.

Knowing how to convert STL files to G-code is essential in 3D printing. It bridges the gap between your digital designs and your printer’s instructions to create objects.

Our simple guide walks you through the process, from selecting the right slicing software to configuring your 3D printer and generating G-code.

What is an STL File?

A model of Batman in Cura slicing software to demonstrate how to Convert STL Files to G code

An STL file is the most common digital file type used in 3D printing and is widely used in Computer-Aided Design (CAD). Chuck Hulk created the file type while working at 3D Systems in the 1980s. While the true meaning of STL is a point of contention, it’s commonly believed to be an abbreviation for stereolithography.

Note: Despite other suggested meanings, such as Standard Triangle Language or Standard Tessellation Language, Stereolithography remains the most accepted origin.

STL files contain data about the surface geometry of a 3D object using a mesh of interconnected triangles, a process known as tessellation.

Each triangle is represented by its vertices and normal vectors, which accurately describe the object’s shape. However, STL files do not include information about color, texture, or other attributes, making them purely geometric data files.

This mesh comprises many small triangles that fit together, forming the whole surface of the object. The more triangles used, the smoother and more detailed the surface.

Most CAD software can create and export STL files. These files are used in 3D printing because they are straightforward and widely supported by 3D printers and slicing software. With less information in the file, STL files are lightweight and fast-loading.

What Are G-Code Files?

The sliced view of a batman statue in Ultimaker’s Cura slicing software

G-code files contain instructions for automated machine tools like 3D printers and CNC machines. This file type translates computer-aided design (CAD) models into instructions that machines can execute to create physical objects. The “G” in “G-ode” stands for “geometry,” reflecting its purpose of defining the geometrical paths that a machine tool will follow.

These files control everything, including the 3D printer’s bed size, speed, path, nozzle temperature, and print temperature.

For instance, commands like G1 X10 Y20 Z10.2 tells your 3D printer to move its print head in a straight line to coordinates (10, 20, 10.2) on the print bed, while commands like M104 S200 set the extruder temperature to 200°C​

You don’t need to write G-code by hand. Instead, you use a slicer program. This software converts your 3D model (like an STL file) into the G-code your machine needs.

So, if you’re 3D printing or CNC machining, G-code files bridge the gap between your digital designs and physical creations.

How to Convert STL Files to G-code

To turn your STL files into G-code for 3D printing, you’ll use slicer software that configures your 3D printing settings and slices the model to generate the G-code.

Here’s a step-by-step guide to help you convert STL files to G-Code:

Step 1: Download A Slicing Software

A screenshot of the Ultimaker Cura Download page

First, you need to download slicing software, which allows you to configure your print settings and slice the model into G-Code.

Popular slicing software includes Ultimaker Cura, PrusaSlicer, and Bambu Studio. These free platforms offer different features, but they all do an excellent job slicing 3D models. So, choose the platform you like the best.

Editor’s Tip

While I’ve used Cura, I’ve begun using Bambu Studio more.

If your 3D printer manufacturer offers a slicing program, it’s best to use that program for compatibility. However, slicing software is universal, and you can get excellent print quality with any popular program.

Once installed, open the slicer to start the next steps.

Step 2: Configure Your 3D Printer

The select a printer screen in Creality Print showing the most recent Ender 3 Models

Before you import your STL file, you must configure the slicing software to work with your 3D printer. This ensures that the generated G-code matches your printer’s specifications, including the bed size, nozzle diameter, and filament material.

After configuring the 3D printer, you can adjust print settings like layer height, print speed, infill, and support. These settings are crucial for accurate prints; you’ll need to tinker with them to achieve the best print quality.

Step 3: Import Your 3D STL File

A low poly skull imported into Creality Print

Now, you’re ready to bring your STL file into the slicer.

You can usually import files by clicking on “File” then “Open” or by dragging and dropping them into the slicing program.

After importing, you can view, rotate, and scale your model to fit your printer build area.

Step 4: Slice and Convert the STL File to G-Code

A screenshot of a sliced G code file of a low poly skull in the Creality Print slicing software

You can now slice the model with your STL file imported and positioned. Slicing divides the model into horizontal layers and generates the G-Code necessary to print each layer.

Click the “Slice” button in your software. After the slicing finishes, review the sliced model to ensure it looks correct. Previewing your model before printing can prevent many print issues. Look for missing supports, incorrect layer heights, or improper part orientation.

Once satisfied with the sliced file, you can save the G-Code to your SDCard or USB and upload it to your 3D printer. Many new printers offer WiFi connectivity, so you can wirelessly send the G-Code to your machine.

How to Print a G-Code File

Modern 3D printer printing figure close up.
Modern 3D printer printing figure close-up.

After transferring the G-Code to your SD card or USB stick, insert it into your 3D printer. Next, make sure your printer is powered on.

From the printer display, navigate to the option to print files. In most Marlin printers, it’s under the “Print” menu option.

Once you’ve selected the G-code file, the printer will heat up the nozzle and print bed and display the printing progress on display. Once the printer reaches the correct temperature, it will begin printing.

The 3D printing process can take several hours, depending on the size and complexity of your model.

I recommend monitoring the first few layers to ensure smooth operation. Most print failures are caused by poor bed adhesion. If you notice issues with the first layers, stop the print to correct the issue.

After the print finishes, wait for your printer to cool down before removing the object from the print bed.

Photo of author
Written by

Marcello co-founded 3D Print Mentor to share his love of 3D printing. Marcello used to own an online 3D printing company, where he sold unique designs and customized novelty gifts. After closing the business, Marcello’s new passion is 3D printing replica movie props and cosplay items.

Related Articles

3D printed engine block model. Technology, industry

14 Crazy 3D Printing Facts

Close up of a hand holding an SD card with an out of focus Ender 3 V3 SE 3d printer in the background

How to Convert STL Files to G-code

Bambu Lap P1P Upgrades with a green PLA printed side panels and a purge bucket

Bambu Lab P1P Upgrades and Modifications