How to add a preview picture to your gcode

I have tried to figure out how the preview pictures are implemented into the gcode like when you send the gcode directly via the Snapmaker Luban software.
Because this is a VERY cool feature I want to know more about it.

Can anybody help me with this?

I want to use another slicer than Snapmaker Luban because I need some more options (and already purchased licences for Simplify3D).

I’ve tried to copy some parts of the Luban code to the S3D code and it seems to be only working if you replace the whole header.
Since I don’t know how important the header data are for the touch screen app and if it affects the print I wanted to ask the professionals here.
There has to be another way to implement pictures than slice it twice with diferent software and edit the gcode…

Maybe there would be a posibility to make a reference to an extra file (for example same file name as the gcode but with extension .png or .jpg)

Since nobody wanted to help me (or is not interested in the feature) I found a workaround (since I don’t know a detail of the SM Luban code) by myself:

Slice the file with Snapmaker Luban and export the gcode as a file (since I only want the picture there is no need to worry about the settings).
Then slice the model with your desired software.
Open both files with a text editor.
Now copy the marked parts from the Luban-created file to the other and save the file:

Now you can send the gcode to the machine and you will see a preview after the parsing (when you copy the complete header the picture is displayed earlier but the displayed values are incorrect).

PS: Since the header only contains the graphic all other values are calculated by the software on the SM2.0 - and the size is including skirt and end script.

PPS: Maybe somebody from the programmers (or anybody interested in this) can discuss with me about my “solution”.

7 Likes

According to our software engineers, the preview picture will appear when you print the G-code that is generated from Snapmaker Luban.

@Edwin This is obvious…

But since the picture is saved as part of the generated gcode it is possible to manipulate codes from other slicers. I have a workaround in my previous post.
At the moment I want to know the specifications of the thumbnail (dimension, resolution,…) and the way how to convert the picture.

PS: The picture of the preview on the TS is showing a gcode created by Simplify3D (with imported thumbnail from Snapmaker Luban).

1 Like
  • Make a screenshot of a model
  • Use PNG/JPG 2 Base64 format convertor to transform the image.
  • e.g: https://www.base64decode.org/
  • Add the characters in the G-code file so that the touchscreen can read and show the image
  • The touchscreen can parse the annotated characters and display the rendered image
3 Likes

I have just hacked up a plugin for Cura, which saves the image automatically in the exported gcode file.

I will try to make a polished version of it and then publish it here in the forum.

12 Likes

So now i have finalized the plugin and put it on GitHub. Instructions are on the Github page.

14 Likes

Thank you! This is great :+1:

This is really great! is it possible to make somthing similar for prusa-slicer?

You can try to load your Gcode from prusa-slicer to cura and try to save it again. Haven’t tried it, but could work.

Will try this, thank you.
But a solution directly in Prusa-slicer would be very nice.
If I could, I would do it by myself, but my coding-knowledge is too bad. :see_no_evil:

I had a look, but prusa-slicer is not extendible through plugins. This would mean we had to fork the prusa-slicer and create our own version. It is possible, but with every new version from prusa somebody had to merge the functionality into the new version every time. Other possibility would be to implement it and do a pull-request and hope that the developers of prusa-slicer adapt this functionality. In either case, it is too much work for me.

2 Likes

I don’t think the prusa developers will do this, just for a few Snapmaker users^^
But thank you for your efforts!! :slightly_smiling_face:

Maybe this is another reason for giving Cura a try :sweat_smile:

@Razor1990: you sir, are the best.
I was already thinking about implementing this myself, but as I have no python experience that would have cost me ages. Your plugin seems to work perfect! Thanks!

I’ve not yet looked into the other gcode differences, but maybe you can expand your plugin to add the other header data that Luban adds as well? And maybe “check if the start/end gcode was set, if not add it”… that would make it the perfect bridge from Cura to the machine, for those who do not like Luban’s limited capabilities.

Is there a way to show these thumbnails in Windows explorer?

Thanks! Just thought about doing this by myself and found this. Great!

I now use cura also, and use your plugin, great work! :slight_smile:

only “problem” I have is, when I save the gcode directly to a USB-Drive, Cura uses the normal gcode-format, not the snapmaker-gcode from your plugin.
Is there a way to change the fileformat which is used when saving directly to usb-drive?

Exactly as you say it. The moment you click “save gcode file” you will have to click the file type drop-down and change it from standard gcode format to the snapmaker gcode format. As the plugin runs “on save”.

I also made a tutorial about this plugin and cura setup, which I also posted on the official support facebook group:

@Razor1990: it got around 80 likes and a lot of positive comments, so your plugin should have had some more downloads lately :wink: (since 21/11)

2 Likes

I am working on a solution to directly send the Gcode over WiFi to the Snapmaker. So stay tuned.:wink:
But as I try to learn something about test-driven development with this project, it might take a bit more.

4 Likes