Thumbnails for Orca 3MF in GNOME Files

I wanted to have previews for 3MF files in GNOME files (nautilus). I came across this project by Rui Carmo which smartly used a simple Python script to extract the existing thumbnail from a 3MF file, but this didn’t work with my Orca Slicer created files.

A simple modification to the 3mf_thumbnailer file helps to search for various thumbnails inside the 3MF, and specifically I’ve set it to look for plate_1.png which Orca Slicer seems to set. Here’s the script:

#!/usr/bin/python3

# Modified from https://github.com/rcarmo/gnome-thumbnailers
# Original Copyright (c) 2022 Rui Carmo - MIT License

from sys import argv
from zipfile import ZipFile

THUMBNAIL_FILENAMES = [
    'Metadata/thumbnail.png',
    'Metadata/plate_1.png',
]

with ZipFile(argv[1], 'r') as zip:
    names = zip.namelist()
    for filename in THUMBNAIL_FILENAMES:
        if filename in names:
            thumbnail = zip.read(filename)
            with open(argv[2], 'wb') as f:
                f.write(thumbnail)
            break

To summarize the full steps (taken from here) of using this:

[Thumbnailer Entry]
Exec=/usr/local/bin/3mf_thumbnailer %i %o
MimeType=application/vnd.ms-3mfdocument;model/3mf;