0
$\begingroup$

on which can save and load custom props (drive shape keys) and pose bone transform for Armature characters as preset.json with some options.

Then I hope to enhance it by generating preview images (jpg, or png) with json. (eg When I save "preset.json" from add on UI button,it will auto generate preset.png of current scene preview)

I suppose I can use the bpy.utils previews submodule (bpy.utils.previews) but do not know clearly how it actually works. What I hope to know is, if there's a function which can generate the preview at a user-defined path.

I suspect I can mix the funciton with my custom operator class to save json (so when save the json, same name image file will be genrated as perview)...

If someone has experience with this, would you teach me how you achieve it (with simple code)?

I suppose I may need to use the bpy.utils.submodule (bpy.utils.previews) but even though I read the docs and example (which uses the image as UI widgt, which I don't need, I only need to know how to generate a current scene preview as image file)

//////

Though my final goal is same, I took some of the steps and made a few changes...

What I planned is,

  1. render and save viewport as open GL image with current user scene settings, when you save "preset.json" from my add-on's UI button

Then I hope to make render and save function, which renders the view port (Open GL) image and saves the image "without image editor>render-image>save"

I plan to use bpy.ops.render.opengl(), to render a thumbnail, is there good way, "without opening the image editor(Render image) and choosing slots" but saving to the directory with file name, as arguments?

Has someone already built a simillar (simple) custom function?

$\endgroup$
3
  • 1
    $\begingroup$ Have you seen: Batch generate preview/thumbnail image for old files? already? $\endgroup$
    – brockmann
    Commented Dec 1, 2020 at 8:09
  • $\begingroup$ Thanks link, yes it teach me some new things, but I feel it is not really what I need. $\endgroup$
    – tokikake
    Commented Dec 2, 2020 at 1:03
  • $\begingroup$ MMMM,, I expect if there should be more simple module function, which I simply generate current scene thumbnail with some arguments ^^; $\endgroup$
    – tokikake
    Commented Dec 2, 2020 at 1:41

1 Answer 1

1
$\begingroup$

It was actually easy. thanks there is already arguments, to direct output render-image in bpy.ops.render.opengl() (write_still = "True")

then most simple case (if keep current scene render setting), once change path(file name) to render thumbnail(openGL view image), then after generate the img , return path as same as before. (so user may not notice it changed)

import bpy

def render_icons(fname):
    render = bpy.context.scene.render
    upath = render.filepath
    render.filepath = fname
    bpy.ops.render.opengl(animation=False, view_context=False, write_still=True)
    bpy.context.scene.render.filepath = upath

I suppose, to enhance this, untill render, set some render propertys of bpy.context.scene.render to fit as thumbnail, then return all property as same as before. and add option flag (user may manually set those setting, or use preset for icon render)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .