Author Topic: Saving Presets and Renders with Built In Python API (Not Automation Toolkit)  (Read 951 times)

Hey Everyone,

I have been doing more scripting for substance lately using the built in Python API. Everything has been working great except I have noticed it seems like there are a few functions missing from the API for whatever reason. Or maybe I just don't know how to trigger them.

So does anyone know if there is a way to save Preset files (.sbsprs), load 3D View state files (.sbsscn), view all outputs in 3D View, and save 3D View renders (and 2D View) using the built in API? This would help tremendously on the tool I'm building as these few things are the only things that aren't automated and the user has to do them manually. To be clear I am not talking about the standalone Substance Automation Toolkit.

Thanks a bunch.


It is not possible today to save presets, view all material outputs or load 3d view states using Python.

Exporting renders and textures from the 2d / 3d view is also not exposed in the Python API at the moment.

Depending on what you need to do, maybe there are some alternatives. If you need to take screenshots for
icons or thumbnails, you can use Qt to retrieve the widget image and save that to a file.

Something like this (untested):

Code: [Select]
def take3DViewScreenShot(uiMgr, fileName):
        all3DViews = []
        self.__findAll3DViews(uiMgr.getMainWindow(), all3DViews)

        if len(all3DViews):
            view = all3DViews[0]
            pixmap = view.grab()
            img = pixmap.toImage()

            print("No 3d views found!!!")

        return None

def __findAll3DViews(widget, widgets):
    if not isinstance(widget, QtWidgets.QWidget):

    if isinstance(widget, QtWidgets.QOpenGLWidget):

    for w in widget.children():
        __findAll3DViews(w, widgets)


Thanks a bunch. Any amount of automation I can get I will take.

Exporting 2d outputs is actually possible within sd api.

Any compositing node output is an SDProperty with SDTexture value. If you get this value you can then save the content to file with All graph output nodes also have this property it's just not connectable (so you can export all the outputs after getting them by SDGraph.getOutputNodes.

Minimal example without error handling and stuff:
Code: [Select]
import sd

ctx = sd.getContext()
app = ctx.getSDApplication()
ui_mgr= app.getUIMgr()

current_graph = ui_mgr.getCurrentGraph()
current_graph.compute() # can be quite long for complex graph
current_node = ui_mgr.getCurrentGraphSelection()[0]

for p in current_node.getProperties(sd.api.sdproperty.SDPropertyCategory.Output):
    if (p.getId() == "output"):
        tex: sd.api.SDTexture = current_node.getPropertyValue(p).get()"D:\output.png") # your path here

This script just saves output with "output" id on selected node to file (you can use any id "output" is usually the main one at least for builtin nodes)

3D is not supported as far as I know (neither by sd api nor pysbs). You can use PBR Render node and export "Beauty" as above, that can be acceptable workaround.