Last updated on
May 24, 2023
- Substance 3D home
- Home
- Command Line Tools
- Command Line overview
- sbsbaker
- sbscooker
- sbsmtools
- sbsmutator
- sbsrender
- sbsupdater
- Command Line overview
- Pysbs - Python API
- Pysbs - Python API overview
- Getting started
- General topics
- Examples
- API Content
- API Content overview
- Substance definitions
- Common interfaces
- compnode
- context projectmgr
- graph
- mdl
- modelgraphindex
- modelannotationnames
- modelgraph
- modelgraphgenerator
- modelgraphimplementation
- modelnodenames
- modeloperand
- modulegraphindex
- moduleannotation
- moduleconnection
- modulegraph
- modulegraphgenerator
- modulegraphimplementation
- modulegraphlibrary
- modulegraphregister
- modulenode
- modulenodeimplementation
- modulenodeinstance
- moduleoperand
- moduleoutputbridging
- moduleparaminput
- params
- projectmgrdoc
- sbsarchive
- sbscommon
- sbspreset
- sbsproject
- substance
- Libraries
- sbsenum
- sbslibrary
- sbsbakerslibrary
- Helpers
- Execution context
- API Change log
- Samples
- Setup and Getting Started
- Integrations
- Substance Maya toolset
- Changelog overview
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()