Author Topic: Pysbs get set parameters on nodes problem  (Read 5164 times)


I might be missing something here but i cant get - set a parameter , like opacity or color.
Support is appreciated.

Thank you.

# Init the context
aContext = context.Context()

aSBSFileAbsPath = 'pathname\Input.sbs'

(works)

# Creation of a SBSDocument object from an existing .sbs file, parsing and writing

sbsDoc = substance.SBSDocument(aContext, aSBSFileAbsPath)
sbsDoc.parseDoc()          # Parse the .sbs file and put into sbsDoc the object structure contained in the substance

(works)

# Getting all the graphs of a package
aGraphList = sbsDoc.getSBSGraphList()

# the graph

aGraph = aGraphList[0]

(works)

# Get a particular node from its uid
myNode = aGraph.getNode(aNode='1289452818')

(works)

uniform_color_node = aGraph.getNode(aNode='1545322112')

(works)

blend_1_node = aGraph.getNode(aNode='1355325589')                                       # Get the resource from its identifier

blend_2_node = aGraph.getNode(aNode='1355352560')

(works)

aGraph.connectNodes(aLeftNode = blend_1_node, aRightNode = blend_2_node)

(works)

PROBLEM STARTS HERE

uniform_color_node.getParameterValue('ColorOutput')
uniform_color_node.setParameterValue('ColorOutput', [1, 0, 0, 1])

blend_1_node.setParameterValue('Opacity', 0)

with error

line 234, in setParameterValue
    raise SBSLibraryError('Parameter '+aParameterName+' cannot be set on '+self.getDisplayName())
pysbs.api_exceptions.SBSLibraryError: Parameter ColorOutput cannot be set on Filter uniform

Your problem is the string you're using to find ColorOutput. It should actually be 'outputcolor'.
uniform_color_node.getParameterValue('ColorOutput')
uniform_color_node.setParameterValue('ColorOutput', [1, 0, 0, 1])


If you're ever unsure, you can grab identifier names by exposing them in Designer, or by using the following:
Code: [Select]
print uniform_color_node.getDefinition().getAllParameterIdentifiers()

Test code:
Code: [Select]
from pysbs import context, substance, sbsenum

###
sbs_path = 'H:/test.sbs'  # Change to your path.

# Build doc.
context = context.Context()
sbs_doc = substance.SBSDocument(context, sbs_path)
sbs_doc.parseDoc()

# Get graph
graph = sbs_doc.getSBSGraphList()[0]

# Get node.
uniform_color_node = graph.getNode(aNode='1355511223')  # Change ID to whatever your file uses.

# Get params.
print uniform_color_node.getDefinition().getAllParameterIdentifiers()  # Shows all available identifiers.
# >>> [u'colorswitch', u'outputcolor', u'outputsize', u'format', u'pixelsize', u'pixelratio', u'tiling', u'quality', u'randomseed']

# Get param value.
out_color = uniform_color_node.getParameterValue('outputcolor')  # Find using string.
#out_color = uniform_color_node.getParameterValue(sbsenum.CompNodeParamEnum.OUTPUT_COLOR)  # Or find using enum.
print out_color 
# >>> 0.0 0.0 0.0 1.0

# Set param value.
uniform_color_node.setParameterValue('outputcolor', [1, 0, 0, 1])
print uniform_color_node.getParameterValue('outputcolor') 
# >>> 1 0 0 1

# Save doc.
sbs_doc.writeDoc()

Oh should have grabbed the parameters first to check them , nice catch there  , many thanks.