Author Topic: createOutputNode throws error when passing a "usages" argument  (Read 660 times)

Hello

I'm using Automation Toolkit 2018.3.0

Somewhere in my code, I have the following line:
Code: [Select]
output = graph.createOutputNode(aIdentifier = identifier, aUsages = usages)usages is defined as:
Code: [Select]
{
pysbs.sbsenum.UsageEnum.HEIGHT: pysbs.sbsenum.ComponentsEnum.R,
pysbs.sbsenum.UsageEnum.METALLIC: pysbs.sbsenum.ComponentsEnum.G,
pysbs.sbsenum.UsageEnum.ROUGHNESS: pysbs.sbsenum.ComponentsEnum.B,
pysbs.sbsenum.UsageEnum.AMBIENT_OCCLUSION: pysbs.sbsenum.ComponentsEnum.A
}
This throws this error:
Code: [Select]
[ERROR][pysbs.api_decorators] Exception of kind AttributeError in pysbs.sbsgenerator, line 564: _resolveUsage()
[ERROR][pysbs.api_decorators] Exception of kind AttributeError in pysbs.sbsgenerator, line 623: createOutputNode()
[ERROR][pysbs.api_decorators] Exception of kind AttributeError in pysbs.graph.graph, line 1585: SBSGraph.createOutputNode()
Traceback (most recent call last):
  File "fixSbs.py", line 146, in <module>
    fixSbs(inputPath, outputPath)
  File "fixSbs.py", line 136, in fixSbs
    pysbs.sbsenum.UsageEnum.AMBIENT_OCCLUSION: pysbs.sbsenum.ComponentsEnum.A
  File "fixSbs.py", line 58, in createOutput
    output = graph.createOutputNode(aIdentifier = identifier, aUsages = usages)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\api_decorators.py", line 54, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\graph\graph.py", line 1585, in createOutputNode
    aVisibleIf = aVisibleIf)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\api_decorators.py", line 54, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\sbsgenerator.py", line 623, in createOutputNode
    outputUsages = [_resolveUsage(usg, usageDict) for usg, usageDict in aUsages.items()]
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\sbsgenerator.py", line 623, in <listcomp>
    outputUsages = [_resolveUsage(usg, usageDict) for usg, usageDict in aUsages.items()]
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\api_decorators.py", line 54, in wrapper
    return function(*args, **kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\pysbs\sbsgenerator.py", line 564, in _resolveUsage
    colorspace = usageData.get(sbsenum.UsageDataEnum.COLOR_SPACE, None)
AttributeError: 'int' object has no attribute 'get'

I'm not sure why this happens because according to the documentation present here: https://docs.substance3d.com/sat/pysbs-python-api/api-content/substance-definition/graph
the usages argument is defined like this:
Code: [Select]
aUsages (dictionary {UsageEnum : ComponentsEnum}, optional) – usage of this output
This was working perfectly fine when I was using the Automation Toolkit 2018.1.0.

I also checked, and removing the argument will stop the error from being thrown.

Is this a bug or am I not using the API correctly?


Yeap as Usages evolve, you must use a nested dict.
For instance (extract from the demoworld.py example)

Code: [Select]
outBaseColor = aGraph.createOutputNode(aIdentifier = 'BaseColor',
                            aGUIPos = baseColor.getOffsetPosition(xOffset),
                            aUsages = {sbsenum.UsageEnum.BASECOLOR:   {sbsenum.UsageDataEnum.COMPONENTS:sbsenum.ComponentsEnum.RGBA}})

And you right the doc must be updated about that.