Modifying G-Code for your 3D prints can seem difficult and confusing at first, but it isn’t too hard to get the hang of. If you want to learn how to modify your G-Code in Cura, this article is for you.
Cura is a very popular slicer among 3D printing enthusiasts. It offers a way for users to customize their G-Code using placeholders. These placeholders are preset commands that you can insert in your G-Code at defined locations.
Although these placeholders are very useful, for users requiring greater editorial control, they can be very limiting. To fully view and edit G-Code, you can use a variety of third-party G-Code editors.
This is the basic answer, so keep on reading for a more detailed guide. In this guide, we will show you how to create, understand and modify G-Code using both Cura and third-party editors.
So, let’s get down to it.
What is G-Code in 3D Printing?
G-Code is a programming language containing a set of commands for controlling virtually all of the printer’s print functions. It controls the extrusion speed, fan speed, heated bed temperature, print head movement, etc.
It is created from the 3D model’s STL file using a program known as a “Slicer”. The slicer transforms the STL file into lines of code that tell the printer what to do at every point throughout the printing process.
Do All 3D Printers Use G-Code?
Yes, all 3D printers use G-Code, it is a fundamental part of 3D printing. The main file that 3D models are made from are STL files or stereolithgraphy files. These 3D models are put through a slicer software to convert into G-Code files which 3D printers can understand.
How Do You Translate & Understand G-Code?
As we said earlier, most of the time, regular users might not even need to edit or modify the G-Code. But sometimes, situations can arise where a user might need to tweak or modify some print settings that can only be found in the printer’s G-Code profile.
In situations like this, knowledge of G-Code can come in handy to help accomplish the task. Let’s go through some common notations in G-Code and what they mean.
In the G-Code programming language, we have two types of commands; the G command and the M command.
Let’s take a look at both of them:
G commands control the different modes of the printer. It is also used in controlling the motion and orientation of the printer’s different parts.
A typical G command looks like this:
11 G1 F90 X197.900 Y30.000 Z76.000 E12.90000; Comment
Let’s go through the line and explain the commands:
- 11 – This indicates the line of code that is running.
- G – The G signifies the line of code is a G command while the number after it represents the printer’s mode.
- F – F is the speed or feed rate of the printer. It sets the feed rate (mm/s or in/s) to the number right after it.
- X/Y/Z – These represent the coordinate system and its positional values.
- E – E is the parameter for the movement of the feeder
- ; – The semi-colon usually precedes a comment on the G-Code. The comment is not part of the executable code.
So, if we put it all together, the line of code tells the printer to move to coordinate [197.900, 30.00, 76.00] at a speed of 90mm/s while extruding 12.900mm of material.
The G1 command means the printer should move in a straight line at the specified feed speed. We’ll look at other various G commands later.
You can visualize and test out your G-Code commands here.
M commands differ from G commands in the sense that they start with an M. They control all the other miscellaneous functions of the printer such as the sensors, heaters, fans, and even the printer’s sounds.
We can use M commands to modify and toggle the functions of these components.
A typical M command looks like this:
11 M107; Turn off part cooling fans
12 M84; Disable motors
Let’s decipher what they mean;
- 11, 12 – These are the lines of the code, to be used as a reference.
- M107, M84 – They are typical end of print commands for the printer to power down.
How To Edit G-Code In Cura
As we mentioned earlier, the popular Ultimaker Cura slicer provides some G-Code editing functionality for users. Users can tweak and optimize some parts of the G-Code to their custom specifications.
However, before we get into the editing of G-Code, it’s important to understand the structure of G-Code. G-Code is structured into three main parts.
Before printing can start, certain activities need to be carried out. These activities include things like pre-heating the bed, turning on the fans, calibrating the position of the hot end.
All these pre-printing activities are in the initialization phase of the G-Code. They are run before any other code snippet.
An example of initialization phase code is:
G90; set the machine to absolute mode
M82; Interpret extrusion values as absolute values
M106 S0; Power on the fan and set the speed to 0.
M140 S90; Heat the bed temperature to 90oC
M190 S90; Wait until the bed temperature reaches 90oC
The printing phase covers the actual printing of the 3D model. G-Code in this section controls the layer-by-layer movement of the printer’s hotend, the feed speed, etc.
G1 X96.622 Y100.679 F450; controlled motion in the X-Y plane
G1 X96.601 Y100.660 F450; controlled motion in the X-Y plane
G1 Z0.245 F500; change layer
G1 X96.581 Y100.641 F450; controlled motion in the X-Y plane
G1 X108.562 Y111.625 F450; controlled motion in the X-Y plane
Printer Reset Phase
The G-Code for this phase takes over after the 3D model finishes printing. It includes instructions for cleanup activities to get the printer back to its default state.
An example of printer end or reset G-Code is shown below:
G28; bring the nozzle to home
M104 S0; turn off heaters
M140 S0; turn off bed heaters
M84; disable motors
Now that we know all the different phases or sections of G-Code, let’s look at how we can edit them. Like most other slicers, Cura only supports editing the G-Code in three places:
- At the start of the print during the print initialization phase.
- At the end of the print during the print reset phase.
- In the printing phase, during layer changes.
To edit G-Code in Cura, you have to follow a set of instructions. Let’s go through them:
Step 1: Download Cura from the Ultimaker site here.
Step 2: Install it, agree to all the terms and conditions, and set it up.
Step 3: Add your printer to the list of printers.
Step 4: When setting up your printing profile, instead of selecting Recommended mode to choose the Custom mode.
Step 5: Import your G-Code file into Cura.
- Click preferences
- Click profile
- Then click import to open a window to import the file
Step 6: Alternatively, you can go to the printer’s settings, click machine settings then enter your G-Code manually.
Step 7: In the printer’s settings, you’ll see tabs for modifying the start and end G-Code for various components like the extruder(s), print head settings, etc.
Here, you can modify various print initialization and reset settings. You can edit commands and also add some of your own.
In the next section, we’ll be looking at some of those commands.
You can use also Cura’s post-processing extension to modify your G-code. Here’s how you can do it.
Step 1: Open Cura and load your file.
Step 2: Click on the extensions tab on the toolbar.
Step 3: Click on extensions, then click on modify G-Code.
Step 4: In the new pop-up window, click on “Add scripts”.
Step 5: A menu will show up containing options like “Pause at height”, “Time lapse” etc. You can use these preset scripts to modify your G-Code.
What are Some Common 3D Printer G-Code Commands?
Now that you know all about G-Code and how to modify it in Cura, let’s show you some commands you can use.
Common G Commands
G1 /G0 (Linear Move): They both tell the machine to move from one coordinate to the other at a certain speed. G00 tells the machine to move at its max speed through space to the next coordinate. G01 tells it to move to the next point at a specified speed in a straight line.
G2/ G3 (Arc or Circle Move): They both tell the machine to move in a circular pattern from its starting point to a point specified as an offset from the center. G2 moves the machine clockwise, while G3 moves it in a counter-clockwise pattern.
G28: This command returns the machine to its home position (machine zero) [0,0,0]. You can also specify a series of intermediate points the machine will pass through on its way to zero.
G90: It sets the machine to absolute mode, where all the units are interpreted as absolute coordinates.
G91: It moves the machine several units or increments from its current position.
Common M Commands
M104/109: Both commands are extruder heating commands they both accept an S argument for the desired temperature.
The M104 command starts heating the extruder and resumes running the code immediately. The M109 waits until the extruder reaches the desired temperature before running other lines of code.
M 140/ 190: These commands are bed heating commands. They follow the same syntax as the M104/109
The M140 command starts heating the bed and resumes running the code immediately. The M190 command waits until the bed reaches the desired temperature before running other lines of code.
M106: The M106 command allows you to set the speed of the external cooling fan. It takes an argument S which can range from 0 (off) to 255 (full power).
M82/83: These commands refer to setting your extruder to absolute or relative mode respectively, similar to how G90 and G91 set the positioning for the X, Y & Z axis.
M18/84: You can disable your stepper motors and can even be set with a timer in S (seconds). E.g. M18 S60 – this means disable steppers in 60 seconds.
M107: This allows you to turn off one of your fans, and if no index is given, it will be the part cooling fan.
M117: Set an LCD message across your screen immediately – “M117 Hello World!” to display “Hello World!”
M300: Play a tune on your 3D printer with this command. It uses M300 with an S parameter (Frequency in Hz) and P parameter (Duration in milliseconds).
M500: Save any of your input settings on your 3D printer to EEPROM file to remember.
M501: Load all of your saved settings within your EEPROM file.
M502: Factory reset – reset all configurable settings to factory defaults. You’ll have to save this by also using M500 afterwards.
Best Free G-code Editors for 3D Printing
Cura is great for editing G-Code, but it still has its limitations. It is only useful for editing certain areas of the G-Code.
If you are an advanced user and you need more freedom to edit and work around your G-Code, we recommend using a G-Code editor.
With these editors, you have the freedom to load, edit and even visualize the various areas of your G-Code. Here is a list of some of the most popular free G-Code editors.
Notepad++ is a juiced-up version of the normal text editor. It can view and edit several file types with G-Code being one of them.
With Notepad, you have standard functionality like search, find and replace, etc to help you in editing your G-Code. You can even unlock additional features like text highlighting by following this simple guide.
Notepad++ might not be the flashiest G-Code editor on the market, but it is quick, easy to use, and lightweight.
NC viewer is for users looking for more power and functionality than what Notepad++ has to offer. In addition to powerful G-Code editing tools like text highlighting, NC viewer also provides an interface for visualizing the G-Code.
With this interface, you can go through your G-Code line by line and view what you are editing in real life. It is important to note that this software was not developed with 3D printers in mind. It is geared towards CNC machines, so some commands might not function well.
gCode is an online G-Code editor built primarily for 3D printing. In addition to providing interfaces for editing and visualizing G-Code, it also accepts information like nozzle size, material, etc.
With this, you can generate and compare different cost estimates for various G-Codes to determine the optimal version.
Finally, a word of caution. Before you edit your G-Code, make sure you back up the original G-Code file in case you might need to reverse the changes.
Also, make sure you calibrate your printer properly before you start using the G commands. Happy editing.