Follow our guide and learn how to generate custom G-codes for colorful prints.

Did you like our 4-color mountain sample print? Then you should try this neat trick with other objects too! All you need to do is to prepare the model and generate custom G-codes for it. Here’s a step-by-step guide on how to do this.

4-color mountain 3D printed with DUAL PRO toolhead

Before you start

Important notice 1: This tutorial is recommended for advanced users only.

Important notice 2: To complete all actions from this guide you’ll need a 3D model you want to print in 4-colors, additive manufacturing software like Netfabb or Meshmixer, and Voxelizer slicer. Also, be prepared to take some notes during the process.

Important notice 3: This guide describes only the G-code generation process. On how to print your object please follow our 4-color mountain printing guide.

Preparing your model and assigning colors

Start with launching Netfabb or Meshmixer. Import the STL file you want to 3D print in 4 colors. It’s best to align your model at the 0.0.0. point of the Cartesian system.

custom g-codes
Sample model ready to be cut in Netfabb software

Now, you need to cut your model into parts in places that you want to stop the fabrication process in order to switch the filament. Use the Z-axis slider to determine the cutting height and take note of these values as you’ll need them later.

We cut our mountain into 3 parts but you can make as many cuts and filament switches as you want.

Export each part as a separate STL file, close Netfabb/Meshmixer and launch Voxelizer.

custom g-codes
Sample model ready to be saved and used to generate custom G-codes

In Voxelizer slicer software choose 3D printing workflow, use Import aligned models option, import all STL files made in Netfabb/Meshmixer, and click Voxelize.

custom g-codes
Aligned model in Voxelizer slicer software

In Voxel editor open Materials toolbar and add new materials that will be later assigned to each part of the model. In our 4-color mountain sample, the bottom part was printed with solid color and two other included gradients but you can modify this according to your preferences. Simply change the type of the material from simple to gradient or complex and set your color mix.

Remember that colors in Materials toolbar do not represent actual material colors! Green color represents the left extruder and the amount of filament you want to extrude from it into the mix. Blue represents the right extruder of DUAL PRO toolhead.

custom g-codes
Assigning extruders and color mixes in Voxelizer

Once you have your colors and gradients ready, switch to Object selection mode, right click on each part of the model and assign the materials that you created earlier.

If you want to achieve smooth color transitions, then remember to start each new part of the model with the same color that ends the previous one. For example, if your gradient in the bottom part is finished with yellow filament, then we recommend starting the middle part with yellow too. Otherwise, you’ll get hard cuts in color at the end of each part.

custom G-codes
Material selection in Voxelizer before generating custom G-codes

Simple way to generate custom G-codes

Unclick Object selection mode and click Show advanced. In the Project tab click Add custom G-code and open its settings by clicking on the gear icon.

custom g-codes
Adding custom G-codes in Voxelizer slicer software

Choose On desired y from the list and click Add. First, you need to set the height for the first filament change after printing the bottom part of your model. In Desired y box type in the height of the model, you know from Netfabb. Then add the following code into the textbox below.

G1 Z? F1000 (Important: “?” needs to be replaced with the height in mm on which you want to stop the extruder)
G0 X0 F2400
M104 S0

This command will:

Stop the extruder and raise it to the assigned Z height.
Move the extruder to the 0 position on the X axis.
Turn off the heaters.

When typing in this command, make sure that the Z value is higher than the Desired y value so the extruder doesn’t touch the model when traveling to 0 positions.

Also, please note that your custom G-codes will stop working at specific stages of printing. To restart the process you need to type in a restart command manually. We described and explained these commands in our 4-color mountain printing guide.

custom g-codes
Z7 value on this picture stands for raising the extruder to 7 mm before moving it to the 0 position because the printed part is 6.6 mm tall

Now you need to repeat the above actions for the middle part of your model or any number of parts between the bottom and top layer of your object. The top part doesn’t require any additional custom G-codes because you will feed the required material before it starts printing.

After you add enough custom G-codes, simply click Generate G-code and save it on your computer or the SD card.

4-color mountain
Blue base of the 4-color mountain sample print

What’s next?

Using this guide you managed to create custom G-codes for a 4-color 3D print that includes color gradients. You can use these tips to create as many filament switches as you want and achieve even more colorful objects as a result – feel free to experiment!

The next logical step would be to 3D print your object using tricks described in our 4-color mountain sample guide.


Content Marketing Manager at ZMorph. 3D printing enthusiast and avid gamer

Write A Comment