demohelloworld | Substance 3D Automation ToolKit

Note

Documentation for Substance Automation Toolkit is now included in the SAT package. You can access the documentation by opening html-doc.zip inside your downloaded SAT package.

demohelloworld

Module demohelloworld provides a very simple example of usage of the Pysbs, without using argument file.

demohelloworld.demoHelloWorld(aDestFileAbsPath)

Create a substance with a very simple material definition: uniform colors for BaseColor, Roughness and Metallic, and save it to ‘sample/resultDemoHelloWorld.sbs’

Parameters: aDestFileAbsPath (str) – The absolute path of the resulting SBS file
Returns: Nothing

Here is the code of function demoHelloWorld:

aContext = context.Context() 
#aContext.getUrlAliasMgr().setAliasAbsPath(aAliasName = 'myAlias', aAbsPath = 'myAliasAbsolutePath') 
 
startPos = [48, 48, 0] 
xOffset  = [192, 0, 0] 
yOffset  = [0, 192, 0] 
 
try: 
    # Create a new SBSDocument from scratch, with a graph named 'SimpleMaterial' 
    sbsDoc = sbsgenerator.createSBSDocument(aContext, 
                            aFileAbsPath = aDestFileAbsPath, 
                            aGraphIdentifier = 'SimpleMaterial') 
 
    # Get the graph 'SimpleMaterial' 
    aGraph = sbsDoc.getSBSGraph(aGraphIdentifier = 'SimpleMaterial') 
 
    # Create three Uniform color nodes, for BaseColor, Roughness and Metallic 
    baseColor = aGraph.createCompFilterNode(aFilter = sbsenum.FilterEnum.UNIFORM, 
                        aParameters = {sbsenum.CompNodeParamEnum.OUTPUT_COLOR: [1, 0, 0, 1]}, 
                        aGUIPos     = startPos) 
 
    roughness = aGraph.createCompFilterNode(aFilter = sbsenum.FilterEnum.UNIFORM, 
                        aParameters = {sbsenum.CompNodeParamEnum.COLOR_MODE: sbsenum.ColorModeEnum.GRAYSCALE, 
                                       sbsenum.CompNodeParamEnum.OUTPUT_COLOR: 0.3}, 
                        aGUIPos     = baseColor.getOffsetPosition(yOffset)) 
 
    metallic = aGraph.createCompFilterNode(aFilter = sbsenum.FilterEnum.UNIFORM, 
                        aParameters = {sbsenum.CompNodeParamEnum.COLOR_MODE: sbsenum.ColorModeEnum.GRAYSCALE, 
                                       sbsenum.CompNodeParamEnum.OUTPUT_COLOR: 0.6}, 
                        aGUIPos     = roughness.getOffsetPosition(yOffset)) 
 
    # Create three Output nodes, for BaseColor, Roughness and Metallic 
    outBaseColor = aGraph.createOutputNode(aIdentifier = 'BaseColor', 
                        aGUIPos = baseColor.getOffsetPosition(xOffset), 
                        aUsages = {sbsenum.UsageEnum.BASECOLOR: {sbsenum.UsageDataEnum.COMPONENTS:sbsenum.ComponentsEnum.RGBA}}) 
 
    outRoughness = aGraph.createOutputNode(aIdentifier = 'Roughness', 
                        aGUIPos = roughness.getOffsetPosition(xOffset), 
                        aUsages = {sbsenum.UsageEnum.ROUGHNESS: {sbsenum.UsageDataEnum.COMPONENTS:sbsenum.ComponentsEnum.RGBA}}) 
 
    outMetallic = aGraph.createOutputNode(aIdentifier = 'Metallic', 
                        aGUIPos = metallic.getOffsetPosition(xOffset), 
                        aUsages = {sbsenum.UsageEnum.METALLIC: {sbsenum.UsageDataEnum.COMPONENTS:sbsenum.ComponentsEnum.RGBA}}) 
 
    # Connect the Uniform color nodes to their respective Output node 
    # (no need to precise aLeftNodeOutput and aRightNodeInput here as there is no ambiguity) 
    aGraph.connectNodes(aLeftNode = baseColor, aRightNode = outBaseColor) 
    aGraph.connectNodes(aLeftNode = roughness, aRightNode = outRoughness) 
    aGraph.connectNodes(aLeftNode = metallic,  aRightNode = outMetallic) 
 
    # Write back the document structure into the destination .sbs file 
    sbsDoc.writeDoc() 
    log.info("=> Resulting substance saved at %s", aDestFileAbsPath) 
    return True 
 
except BaseException as error: 
    log.error("!!! [demoHelloWorld] Failed to create the new package") 
    raise error
demohelloworld.main()

Adobe, Inc.

Get help faster and easier

New user?