Skip to content

How to generate a gcode preview

Miguel Risco-Castillo edited this page Oct 10, 2024 · 57 revisions

This firmware allows to show a preview (DACAI and TJC screens may need a firmware upgrade) of G-codes that have a jpeg thumbnail (maximum of 20kbytes) coded in base64 and automatically embedded using a script by the slicer.

In order to see the thumbnail preview three requirements must be met: The slicer must embed the thumbnail data in the G-code file in a compatible way; The printer firmware must support thumbnail (The Professional firmware supports that), The display unit must be prepared to receive and display the thumbnail data, unfortunately, for the latter, you only can be sure by opening the screen unit and comparing it with pictures of different types of display units. It is easy to know if you meet the two last requirements by opening a demo G-code with proper formatted thumbnail data, you can find that demo file here (use right-click and select save link as...)

Warning! if you send the g-code file to the µSD using Octoprint, the thumbnail and any other information additional to pure g-code could be stripped. Only transfer by Marlin BFT are untouched.

Note: Your G-code file name must have only standard characters, do not use Chinese, Russian or other special characters.

CHEP video review of the g-code preview feature: https://youtu.be/Q-OA9_t9bGc

CHEP video review of the g-code preview

For be able to generate g-code with thumbnail it is necessary to install Python 3 and a script/plugin in your slicer. Prusa/Super Slicer also requires the Python Pillow library. The scrips are only tested with the latest stable slicer version. There is no guarantee of support for unstable versions (Alpha, Beta, etc.)

First download the correct script/plugin:

Use right-click and select "save link as..." open the file with a text editor, compare with the file posted here and follow the procedure described bellow.

Install the script/plugin

For Orca/Prusa/Super Slicer

Note: Users of Windows and Orca/Prusa/Super Slicer can use an executable file, created by Giadej, which allows the generation of the g-code thumbnail preview, simply by entering the path of the executable in the slicer's post-processing box.

Save the downloaded script in a known location

Prusa 2

Write the location of your Python installation and script on the slicer Print settings / Output options:

Prusa 3

For Orca the location of the Post-processing-Scripts box is at Prepare / Process / Others, you may need to enable the Advanced switch:

Orca Scripts

Prusa/Supe slicer requires expert mode to be enabled in the upper right corner of the program to see the setting. In printer settings / General write 230x180 (180x180 for TJC display) for the G-code thumbnails.

Prusa 1

For Prusa Slicer v2.4+
PrusaSlicer2.4+

For Prusa Slicer v2.5+
PrusaSlicer2.5+

For Orca Slicer
Orca thumbnails

MAC advices

Most MAC come with python2 installed from factory, install and verify that you have python3. You might need to open a Mac terminal and type "which python3" without quotes. This will output the python3 path, for example: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3

This path will then need to be copied into the post processing section of PrusaSlicer, followed by a space, then the path to the python script. Like this:

/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Users/username/Desktop/GCodePreview/PrusaSlicer_JPEG_Preview.py;

All in one line. Also check that you have the Pillow library installed.

For Cura

Go to the Help menu on Cura and select Show Configuration Folder in Windows you will get an explorer opened in the path inside of your user profile folder: C:\Users\NameOfUser\AppData\Roaming\cura\..., Close Cura and save the downloaded script in the scripts folder:

Cura 1

Open Cura, go to menu Extensions > Post Processing > Modify G-Code and press Add a script, then select the script from the post processing plugin popup

Cura 2

Pay attention to the name of the selected script Professional firmware support

Octoprint

Because the printer does not have the preview data if you print from Octoprint, it is not possible to show in the printer display, if you want to see the generated thumbnail in Octoprint, you must to install the plugin Slicer Thumbnails

Slicer Thumbnails

Troubleshooting

Open your script file with a text editor and compare with the posted file maybe it is corrupt. Check if the extension of the file is *.py and not *.py.txt (some computers could hide the file extension)

Header from the Prusa / Super Slicer script:

#!/usr/bin/env python3

# ------------------------------------------------------------------------------
# Prusa / Super Slicer post-processor script for the Professional Firmware
# URL: https://github.com/mriscoc/Ender3V2S1
# Miguel A. Risco-Castillo
# version: 1.5
# date: 2022/05/29
#
# Contains code from the jpg re-encoder thumbnail post processor script:
# github.com/alexqzd/Marlin/blob/Gcode-preview/Display%20firmware/gcode_thumb_to_jpg.py
# ------------------------------------------------------------------------------
...

Header from the Cura script:

#------------------------------------------------------------------------------
# Cura JPEG Thumbnail creator
# Professional firmware for Ender3v2
# Miguel A. Risco-Castillo
# version: 1.4
# date: 2022-05-18
#
# Contains code from:
# https://github.com/Ultimaker/Cura/blob/master/plugins/PostProcessingPlugin/scripts/CreateThumbnail.py
#------------------------------------------------------------------------------
...

Remove the pycache folder from the path where you saved the script.

In Windows it is possible to check where is Python installed with the command (open a cmd window)

>where python
C:\Python\python.exe   <-- It is an example and depends on your Python installation

Open a terminal and confirm that your Python installation is ok:

>python -V
Python 3.10.4   <-- Could be other 3.X.X version (V is in uppercase)

Check if you have Pillow installed:

>pip3 list Pillow
Package Version
------- -------
Pillow  9.1.1   <-- Pillow must be on the list!

Installing the Pillow Python library

Some systems come with python2 installed from factory, which does not incorporate pip. Users are required to install python3, which ships with pip3.

Also, Pillow library could be missing, to install it use:

pip install Pillow

or

pip3 install Pillow

QR code screen glitches

If you get a screen as the image then you have an incompatible font in your screen unit. You can try to correct this, flashing your screen unit with a compatible display asset: https://github.com/mriscoc/Ender3V2S1/wiki/How-to-update-the-display

QRGlitches

DACAI screen units

The current Ender 3S1 and some new Ender 3V2 that have a DACAI screens may need a firmware upgrade, download the firmware from display assets. Put the firmware.zlib file in the root of your µSD card and install it in the screen unit. Versions of DACAI displays known to work with G-Code Preview: v1.1, v1.2, v1.3, v1.4 and v1.5

No-preview-in-DACAI