Author Topic: Save bitmap outputs via python api  (Read 319 times)

So sorry about the rookie question, but I've been staring at the python api docs for hours and can't seem to figure out how to do a simple thing:  SAVE the (one and only) output node 2d bitmap as a jpg.  I have a reference to the correct node in my code, have made all the changes I need via code, and I want to save the output.  Help. ;)  In case it helps you understand where I am at, here is my code (yes, adapted from a demo):

Code: [Select]
import os
import glob
from pysbs import sbsenum
from pysbs import context
from pysbs import substance
from pysbs import batchtools

aContext = context.Context()

xOffset = [150, 0, 0]
yOffset = [0, 150, 0]
initPos = [0, 0, 0]

# Open a sbs file
sbsDoc = substance.SBSDocument(aContext, FILE_PATH)

aGraph = sbsDoc.getSBSGraph(aGraphIdentifier='graphid')

# Retrieve bitmaps
aPathInputs = sbsDoc.mDirAbsPath + os.path.sep
aListInputs = glob.glob(aPathInputs+"*.jpg")

for x in range(0, len(aListInputs)):
    # Create a Bitmap node
    aBitmapNode = aGraph.createBitmapNode(aSBSDocument=sbsDoc,
                                            aGUIPos=[y * x for y in yOffset],

    aId = aListInputs[x][aListInputs[x].rfind(os.path.sep)+1:-4]

    trans2dnode = aGraph.getAllFiltersOfKind(sbsenum.FilterEnum.TRANSFORMATION)[0]

    output = aGraph.getGraphOutputs()[0]

Need a bit of clarification on what you're trying to achieve here.

From reading your post, it seems like you want to add a bitmap, connect it to the transform node and then render the output. Is that a fair assumption?

If that's the case, then there's a couple of things that need to be accounted for:
  • The transform node needs to be connected to one of the output channels (nodes), most likely base_color is what you want.
  • Pysbs is intended to create or modify sbs files so a different process is required to render/export the channels from your graph.

SAT is a combination of command line scripts (sbsbaker, sbsrender, sbscooker, others.) and pysbs.
However, pysbs includes a wrapper for the command line scripts called batchtools, which can be used to run the CLI's as subprocesses via python.

You already have batchtools imported in your example, you can utilize it by calling batchtools.sbsrender_render:
The supported arguments can be found under the sbsrender CLI docs:

Edit: To expand a little bit more, your python script should eventually be compartmentalized like this:
  • Create the sbs package (pysbs; most of this is done in the script you posted)
  • Save the sbs package (pysbs)
  • Run the sbs package through sbscooker (batchtools/CLI); this will generate a flattened sbsar
  • Run the sbsar through sbsrender (batchtools/CLI); this will generate your textures/renders
Last Edit: July 09, 2020, 06:21:56 pm

Hey, @NevTD!

Thanks so much for the reply!  Yes, you understood what I am after perfectly.  I am making filters that will take in a jpg and spit out another seamless jpg.  So yes, as you put it, I will "add a bitmap, connect it to the transform node and then render the output".  Exactly.

Ok the steps you outlined at the bottom appear to be exactly what I needed to know.  I couldn't seem to figure out the difference between baking, cooking, and rendering, lol, and also I didn't realize I needed to save an sbsar file first.  I will try that.  Thanks again!!!