Skip to content

How to generate a gcode preview

Andrew edited this page Nov 26, 2024 · 10 revisions

Read this FIRST:

You should use 200x200 for thumbnail size!

  • Ignore anything that says 230x180 and use 200x200 instead.

This firmware allows to show a preview (DACAI screens may need a firmware upgrade) of G-code 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 micro SD card using Octoprint, the thumbnail and any other information additional to pure G-code could be stripped.
Test if your firmware and screen are capable to show a preview; use this G-code test file (use right-click and select "save link as...")

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

Prerequisites

To 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 scripts 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

  • Find which Python version you have and it's directory location.
    Open CMD Command Prompt and type
    python --version or python3 --version
    where python or where python3
C:\Users\User>python --version
--> Python 3.11.4

C:\Users\User>python3 --version
--> Python 3.10.12
C:\Users\User>where python
--> C:\Program Files\Python311\python.exe
--> C:\Program Files\msys64\mingw64\bin\python.exe
--> C:\Users\User\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\User>where python3
--> C:\Program Files\msys64\mingw64\bin\python3.exe
--> C:\Users\User\AppData\Local\Microsoft\WindowsApps\python3.exe
  • Then take that information and enter it into PrusaSlicer like so:

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 > Post-processing scripts

Prusa 3

Requires expert mode to be enabled in the upper right corner of the program to see the setting.
In Printers > General > Firmware, write 200x200/JPG for the G-code thumbnails.

Prusa 1

MAC devices

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. 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 scripts section of PrusaSlicer, followed by a space, then the path to the python script.
All in one line, like this:

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

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\<User>\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.
You may need to add the value 200 like so:

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

Remove cache

Try removing the pycache folder from the path where you saved the script.

Check Python

In Windows, open a CMD window to check where Python is installed with these commands:

>python -V
Python 3.10.4   <-- Could be other 3.1.X version (V is in uppercase)
>where python
C:\Python\python.exe   <-- It is an example and depends on your Python installation

Check if you have Pillow installed

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

Check Headers

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

# ------------------------------------------------------------------------------
# Orca / Prusa / Super Slicer post-processor script for the Professional Firmware
# URL: https://github.com/mriscoc/Ender3V2S1
# Miguel A. Risco-Castillo
# version: 2.2
# date: 2023/12/10
#
# Contains code from the jpg re-encoder thumbnail post processor script:
# github.com/alexqzd/Marlin/blob/Gcode-preview/Display firmware/gcode_thumb_to_jpg.py
# ------------------------------------------------------------------------------

Header from the Cura script

#------------------------------------------------------------------------------
# Cura JPEG Thumbnail creator post processing script
# MRiscoCProUI firmware
# Miguel A. Risco-Castillo
# ClassicRocker883
# version: 2.2
# date: 2024-05-25
#
# Contains thumbnail code from:
# https://github.com/Ultimaker/Cura/blob/master/plugins/PostProcessingPlugin/scripts/CreateThumbnail.py
#------------------------------------------------------------------------------

Installing the Pillow Python library

Some systems come with python2 installed from factory, which does not incorporate pip. Install pip using:

python3 -m ensurepip --upgrade

-OR-

python3 get-pip.py

Pillow library could be missing, to install it use:

pip install --upgrade Pillow

You may also add python3 -m as prefix before pip to suppress any warnings.

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/classicrocker883/MRiscoCProUI/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 micro 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