Hello
I'm certainly missing something but I d'ont know what ? I'm trying to use the same code to create a SnapShot .. I can get a file but the result is absolutly not correct. If Im using the plugin UPFWriter I got the result thumbnail.png ( the first image) and my result is my_thumbnail.png (the second image) ?
Actual source code
# Copyright (c) 2020 # The SimpleShapes plugin is released under the terms of the AGPLv3 or higher. from PyQt5.QtCore import QObject from PyQt5.QtCore import QBuffer from UM.Extension import Extension from cura.CuraApplication import CuraApplication from cura.Snapshot import Snapshot from cura.Utils.Threading import call_on_qt_thread from UM.Application import Application from UM.Logger import Logger from UM.Message import Message from UM.MimeTypeDatabase import MimeTypeDatabase, MimeType from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") class CreateSnapShot(Extension, QObject,): def __init__(self, parent = None) -> None: QObject.__init__(self, parent) Extension.__init__(self) # attention pas le même nom que le menu self.addMenuItem(catalog.i18nc("@item:inmenu", "Snap"), self.doExtendedCreateTrainingPics) self._snapshot = None def doExtendedCreateTrainingPics(self): self.doCreateTrainingdata(True) #def doExtendedWrite(self): # self.write(stream) @call_on_qt_thread def doCreateTrainingdata(self, extended_mode): self._write() self._message = Message(catalog.i18nc("@info:status", "Creating .PNG pics"), title = catalog.i18nc("@title", "PNG Pics")) self._message.show() def _createSnapshot(self, *args): # must be called from the main thread because of OpenGL Logger.log("d", "Creating thumbnail image...") try: self._snapshot = Snapshot.snapshot(width = 300, height = 300) except Exception: Logger.logException("w", "Failed to create snapshot image") self._snapshot = None @call_on_qt_thread def _write(self): self._createSnapshot() #Store the thumbnail. if self._snapshot: thumbnail_image = self._snapshot thumbnail_image.save("C:/temp/thumbnail.png", "PNG") Logger.log("d", "Thumbnail creation") else: Logger.log("d", "Thumbnail not created, cannot save it")
Edited by Cuq
Recommended Posts
ahoeben 2,026
You could have a look at how the UFP Writer plugin creates thumbnails.
Link to post
Share on other sites
nallath 1,125
Interesting idea! I'd love to hear about your progress. if you need any specific advice on how to make the plugin, feel free to contact me.
Link to post
Share on other sites
Hanshogeland 0
Hi, Thx for you answers.
I have started to try to at least get the cura plugin to start and I´ve gotten so far that I cover the basic Menu item, however I copied the code from the UFP writer and tried to get the method rolling, but I´m stuck at understanding how to get the stream into the method, since I want to to run the script from the menu item I guess I need to add something by the start to access the stream. As you´ll see below I´m pretty novice on this - the out commented Write method need the input stream.
Link to post
Share on other sites