Save Thumbnail on Scene Save#
This example plugin updates the scenefile thumbnail every time a scenefile gets overwritten.
By default Prism saves thumbnails only when saving new versions.
See the section for Single File Plugins on how to load this example.
# SaveThumbnailOnSceneSave.py
name = "SaveThumbnailOnSceneSave"
classname = "SaveThumbnailOnSceneSave"
import os
from qtpy.QtWidgets import *
class SaveThumbnailOnSceneSave:
def __init__(self, core):
self.core = core
self.version = "v1.0.0"
self.core.registerCallback("sceneSaved", self.sceneSaved, plugin=self)
def sceneSaved(self):
if not self.core.getConfig("globals", "capture_viewport", config="user", dft=True):
return # return if capturing thumbnails is turned off in the user settings
filepath = self.core.getCurrentFileName()
if os.path.exists(filepath) and os.path.getctime(filepath) == os.path.getmtime(filepath):
return # return if the scenefile creation time is the same as the modification time, because for new versions Prism already creates a thumbnail by default
appPreview = getattr(self.core.appPlugin, "captureViewportThumbnail", lambda: None)()
if not appPreview:
return # return if no thumbnail could be captured
preview = self.core.media.scalePixmap(appPreview, self.core.scenePreviewWidth, self.core.scenePreviewHeight, fitIntoBounds=False, crop=True)
self.core.entities.setScenePreview(filepath, preview)