Skip to content

How to generate a gcode preview

Miguel Risco-Castillo edited this page May 25, 2023 · 57 revisions

This firmware allows to show a preview (DACAI 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. 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. For test if your firmware and screen are capable of show a preview use this gcode test file (use right-click and select save link as...)

Note: Your G-code file name must have only standard characters, no not use Chinese, Russian or others 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 Prusa/Super Slicer

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

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

Prusa 1

For Prusa Slicer v2.4+
PrusaSlicer2.4+

For Prusa Slicer v2.5+
PrusaSlicer2.5+

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 Create JPEG Thumbnail

Cura 3

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.1.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