Copy link to clipboard
Copied
Hello,
How do I go about exporting through scripting while being able to control export settings and what output nodes get exported?
sd.tools.export.exportSDGraphOutputs
This function is not adequate. I'm unclear on how to disable certain nodes of import and export. This function doesn't seem to help:
current_graph.setOutputNode(o, False)
How come exportSDGraphOutputs doesn't set the names of the exported textures correctly? It just labels them "{graphname}_output_0.png, {graphname}_output_1.png, etc".
How do I configure exporting through a python script similar to how the "Export outputs" window lets you when you right click on a graph and select "Export outputs as bitmaps".
Essentially, I'd like a one button export script that lets me specify:
Cheers
Hey Anomie,
I had a similar problem a few days ago, so this is what I've done.
The
sd.tools.export.exportSDGraphOutputs
is just this little method here:
##########################################################################
# ADOBE CONFIDENTIAL
# ___________________
# Copyright 2010-2024 Adobe
# All Rights Reserved.
# * NOTICE: Adobe permits you to use, modify, and distribute this file in
# accordance with the terms of the Adobe license agreement accompanying it.
# If you have received
...
Copy link to clipboard
Copied
Hey Anomie,
I had a similar problem a few days ago, so this is what I've done.
The
sd.tools.export.exportSDGraphOutputs
is just this little method here:
##########################################################################
# ADOBE CONFIDENTIAL
# ___________________
# Copyright 2010-2024 Adobe
# All Rights Reserved.
# * NOTICE: Adobe permits you to use, modify, and distribute this file in
# accordance with the terms of the Adobe license agreement accompanying it.
# If you have received this file from a source other than Adobe,
# then your use, modification, or distribution of it requires the prior
# written permission of Adobe.
##########################################################################
import os
from sd.api.sbs import sdsbscompgraph
from sd.api import sdproperty
from sd.api.apiexception import APIException
def exportSDGraphOutputs(
aSDGraph,
aOutputDir = '',
aFileExt = 'png'):
"""
Export the textures of the output node of the specified sSDGraph
:param aSDGraph: The graph that contains the outputs to export
:param aOutputDir: The output directory used to save the output's images
:return: True if succeed else False
"""
if not aSDGraph:
return False
if not issubclass(type(aSDGraph), sdsbscompgraph.SDSBSCompGraph):
return False
# Compute the SDSBSCompGraph so that all node's textures are computed
aSDGraph.compute()
# Get some information on the graph
graphIdentifier = aSDGraph.getIdentifier()
# Iterate on nodes
nodeIndex = -1
for sdNode in aSDGraph.getOutputNodes():
nodeIndex = nodeIndex + 1
nodeDefinition = sdNode.getDefinition()
outputProperties = nodeDefinition.getProperties(sdproperty.SDPropertyCategory.Output)
for outputProperty in outputProperties:
# Get the property value
propertyValue = sdNode.getPropertyValue(outputProperty)
# Get the property value as texture
propertyTexture = propertyValue.get()
if not propertyTexture:
continue
# Save the texture on disk
fileExt = aFileExt
fileName = str(graphIdentifier) + '_output_'+ str(nodeIndex) +'.'+ str(fileExt)
textureFileName = os.path.abspath(os.path.join(aOutputDir, fileName))
try:
propertyTexture.save(textureFileName)
except APIException:
print('Fail to save texture %s' % textureFileName)
return True
You can easily edit it or make your own method out of it, with everything you want. I for example used the Output Identifier to label the exports instead of the index, like the original method does it.
The magic method you want to look into is the
propertyTexture.save(textureFileName)
you find everything you need to change the exported format in the API Documentation look for the sd texture module.
Stay healthy and creative Marco
Copy link to clipboard
Copied
Cheers Marco!
That's exactly what I needed. Didn't realize I could just save the output texture directly which gives precise control. I can confirm that my code does what I need now.
Thank you!
Copy link to clipboard
Copied
I'm glad that zi could help. Usually the source files of the python API are compiled cpython modules with python bindings, so almost no chance to change the source code, but the tools section in the API is an exception.
Since the Documentation is not as good as it could be, you can often learn more about the methods, by searching though the source files, just search for the sd folder in the python API in the Designer Directory.
Stay healthy and creative Marco
Copy link to clipboard
Copied
Hello,
In addition to @Marco Vitale's great reply, you may be interested to learn about the SBSRender tool which is included in Designer's installation, next to its executable.
Using this tool, you can export any output(s) of an SBSAR file, with per-output control over resolution, name, filetype and colorspace. It is easy enough to use Python to build the command to call SBSRender with the desired parameters.
Best regards.