Here's a quick snippet that explains the process of adding a new node to an existing pixel processor.
import sd
import sdplugins
from sd import logger
from sd.api import sdproperty, sdbasetypes
from sd.api.sdvaluestring import SDValueString
sd_log = logger.Logger()
class pixelProcessorTest(sdplugins.Plugin):
sPluginDesc = sdplugins.PluginDesc(
aLabel = 'pixel_processor_test',
aTooltip = 'Add string function to all pixel processor nodes in graph.',
aPluginLocation = sdplugins.PluginLocationMenu(sdplugins.MenuId.Scripts, '', 0),
aIconFileAbsPath = '')
def run(self, aContext) :
""" Add a 'Hello' string function node to all pixel processor nodes in first graph. """
pkg = aContext.getSDApplication().getPackageMgr().getUserPackages()[0] # Target first package only.
graph = pkg.getChildrenResources(False)[0] # Target first graph only.
# Query all nodes for the pixelprocessor node definition.
# Docs: Substance Designer Python API 2018.3.1 documentation » Modules Definitions » sbs::compositing.
# ('sbs::compositing::pixelprocessor', 'perpixel')
pp_nodes = []
for node in graph.getNodes():
if node.getDefinition().getId() == 'sbs::compositing::pixelprocessor':
pp_nodes.append(node)
# Iterate through all pixel processors and add string function.
# Docs: Substance Designer Python API 2018.3.1 documentation » Modules Definitions
if pp_nodes:
for node in pp_nodes:
pp_func_prp = node.getPropertyFromId('perpixel', sdproperty.SDPropertyCategory.Input)
pp_graph = node.getPropertyGraph(pp_func_prp) # Returns SDSBSFunctionGraph.
# If pixel processor function graph doesn't exist, create it.
if not pp_graph:
pp_graph = node.newPropertyGraph(pp_func_prp, 'SDSBSFunctionGraph')
# Create and edit node.
# Docs: Substance Designer Python API 2018.3.1 documentation » Modules Definitions » sbs::function.
# ('sbs::function::const_string')
fnc_str_node = pp_graph.newNode('sbs::function::const_string') # Returns SDSBSFunctionNode.
fnc_str_node.setInputPropertyValueFromId('__constant__', SDValueString.sNew('Hello'))
fnc_str_node.setPosition(sdbasetypes.float2(200, 0))
else:
sd_log.log('No pixel processors found in graph. Do nothing.', logger.LogLevel.Warning)
# Register module classes
sd.getContext().getSDApplication().registerModule(__name__)