User Guide Cancel

context | Substance 3D Automation ToolKit

  1. Substance 3D home
  2. Home
  3. Command Line Tools
    1. Command Line overview
    2. sbsbaker
      1. sbsbaker overview
      2. sbsbaker command line options
      3. sbsbaker Example Command Lines
    3. sbscooker
      1. sbscooker overview
      2. sbscooker command line options
      3. sbscooker pattern variables
    4. sbsmtools
      1. sbsmtools overview
      2. sbsmtools command line options
    5. sbsmutator
      1. sbsmutator overview
      2. sbsmutator command line options
      3. sbsmutator Example Command Lines
    6. sbsrender
      1. sbsrender overview
      2. sbsrender base parameters and pattern variables
      3. sbsrender command line options
      4. sbsrender example command lines
    7. sbsupdater
      1. sbsupdater overview
      2. sbsupdater command line options
  4. Pysbs - Python API
    1. Pysbs - Python API overview
    2. Getting started
    3. General topics
      1. Basic manipulation
      2. Substance creation
      3. Substances modification
      4. Dependencies management
      5. PySbs batchtools module
      6. metadata manipulation
      7. SAT demos
      8. Edit sbsar with SBSARManager
      9. Spot Colors
      10. Thumbnail creation with SAT
    4. Examples
      1. demohelloworld
      2. demos
      3. demos_batchtools
      4. script_update_with_sbsupdater
    5. API Content
      1. API Content overview
      2. Substance definitions
        1. Common interfaces
          1. basegraph
          2. package
          3. sbsarobject
          4. sbsobject
        2. compnode
          1. compnode overview
          2. common
          3. compimplementation
          4. paramgraph
        3. context projectmgr
        4. graph
          1. graph overview
          2. function
          3. inputparameters
          4. output
        5. mdl
          1. mdlannotation
          2. mdlcommon
          3. mdldictionaries
          4. mdlenum
          5. mdlgraph
          6. mdllibclasses
          7. mdlmanager
          8. mdlnode
          9. mdlnodeimpl
          10. mdloperand
          11. mdlsbsbridge
        6. modelgraphindex
          1. modelannotationnames
          2. modelgraph
          3. modelgraphgenerator
          4. modelgraphimplementation
          5. modelnodenames
          6. modeloperand
          7. modulegraphindex
          8. moduleannotation
          9. moduleconnection
          10. modulegraph
          11. modulegraphgenerator
          12. modulegraphimplementation
          13. modulegraphlibrary
          14. modulegraphregister
          15. modulenode
          16. modulenodeimplementation
          17. modulenodeinstance
          18. moduleoperand
          19. moduleoutputbridging
          20. moduleparaminput
        7. params
          1. params overview
          2. dynamicvalue
          3. paramnode
        8. projectmgrdoc
        9. sbsarchive
          1. sbsarchive overview
          2. sbsarenum
          3. sbsargraph
          4. sbsargui
          5. sbsarguiwidgets
          6. sbsarmanager
        10. sbscommon
          1. connections
          2. gui
          3. nodes
          4. values
        11. sbspreset
        12. sbsproject
        13. substance
          1. substance overview
          2. content
          3. resource
      3. Libraries
        1. sbsenum
        2. sbslibrary
          1. sbslibrary overview
          2. sbsdictionaries
          3. sbsfilters
          4. sbsfunctions
          5. sbsfxmapnodes
          6. sbslibclasses
          7. sbswidgets
        3. sbsbakerslibrary
          1. sbsbakerslibrary overview
          2. sbsbakersdef
          3. sbsbakersdefaultprops
          4. sbsbakersdictionaries
          5. sbsbakersenum
          6. sbsbakingconverter
          7. sbsbakingconverterparam
          8. sbsbakingparameters
          9. sbsdialogstate
          10. sbsscenedata
        4. Helpers
          1. sbscleaner
          2. sbsexporter
          3. sbsgenerator
          4. sbsparser
          5. sbswriter
          6. qtclasses
            1. qtclasses overview
            2. qtvariantreader
            3. qtvariantwriter
          7. psdparser
          8. sbsimpactmanager
          9. batchtools
          10. autograph
            1. ag_functions
            2. ag_layout
            3. ag_types
          11. info_mesh_parser
          12. sbsbaker_info_handlers
          13. sbsrender_render_handlers
          14. output_handlers
          15. spotcolorinfo_handler
          16. thumbnail
          17. batchtools overview
        5. Execution context
          1. context
          2. functions
        6. API Change log
  5. Samples
    1. Samples overview
    2. Texturing Template Demo
    3. Batch Tools Demo
    4. Variations
    5. Texture Mat
    6. Pixel Processor Ray tracer
  6. Setup and Getting Started
    1. Setup and Getting Started overview
    2. Compatibility
    3. Frequently asked Questions
    4. Known issues
    5. SAT Cookbook
    6. Use Pysbs in different python interpreter (maya, sd, blender...)
  7. Integrations
    1. Substance Maya toolset
      1. Substance Maya Toolset overview
      2. Installing
      3. Launching
      4. Baking
        1. Baking overview
        2. Export parameters
        3. Baker parameters
        4. Mesh setup
        5. Using a template
      5. Changelog
  8. Changelog overview

context

Module context provides object relatives to the execution environment (file path, platform, aliases for package).

 class context.Context(aUrlAliasMgr=None, aMDLManager=None, aProjectMgr=None)  

Bases: object

Class used to purpose information on the application environment

 ActiveModuleRegister = None  
 ModuleRegisters = {}  
 addMDLRootPath(aPath)  

Add the given path to the existing MDL root path list

Parameters:aPath (str) – The absolute path to add as a MDL root path
 addSBSObjectToResolve(aSBSObject)  

When parsing a .sbs file, some objects need the parsing to be complete to finalize their initialization and resolve their dependencies (the CompInstance for example). In order to do so, they must register to the context by calling addSBSObjectToResolve when they are parsed.

Parameters:aSBSObject (SBSObject) – The object to register for later resolution
 static canReadSBSPackage(aFormatVersion, aUpdaterVersion)  

Check if a SBS package with the given format version and updater version can be read by the API.

Parameters:
  • aFormatVersion (string) – the format version of the package
  • aUpdaterVersion (string) – the updater version of the package
Returns:

True if the package is compatible with this API, False otherwise

 static clonePackage(aSBSDocument)  

Create a deep copy of the given document

Parameters:aSBSDocument (SBSDocument) – The SBSDocument to clone
Returns:The new document as a SBSDocument
 static declarePackage(aSBSDocument)  

Add the given SBSDocument to the list of known packages on the Context

Parameters:aSBSDocument (SBSDocument) – The SBSDocument to declare
 static getAutomationToolkitInstallPath()  

Get Substance Automation Toolkit installation path

Returns:The installation path as a string
 static getBatchToolExeName(aBatchTool)  

Get a batch tool executable name

Parameters:aBatchTool (BatchToolsEnum) – The batch tool to get
Returns:The executable path as a string
 static getBatchToolExePath(aBatchTool, aBatchToolsFolder=None)  

Get the batch tool executable corresponding

Parameters:
  • aBatchTool (BatchToolsEnum) – The batch tool to get
  • aBatchToolsFolder (str, optional) – The batch tools folder path. If not provided, use the Substance Automation Toolkit installation folder.
Returns:

The executable path as a string

 static getDefaultPackagePath()  

Get the default resource package path, which corresponds to the alias sbs://

Returns:The resource package path as a string
 getMDLMgr()  

Get the mdl manager

Returns:a MDLManager
 static getMDLRootPaths()  

Get the list of MDL root paths

Returns:The MDL root paths package path as a list of strings
 static getPSDParseExePath()  

Get PsdParse executable path, which is provided by Substance Automation Toolkit

Returns:The executable path as a string
 static getPackage(aAbsPath)  

Look for the given absolute path in the already parsed package and return it if found.

Parameters:aAbsPath (str) – Absolute path of the package
Returns:a SBSDocument if found, None otherwise
 getProjectMgr(aSbsPrjFile=None)  

Get the project manager if a path is given, it will be parsed by the ProjectMgr :param aSbsPrjFile: :return: a ProjectMgr

 static getSBSARFormatVersion()  

Get the SBSAR format version compatible with this version of the API.

Returns:The format version as a string
 static getSBSFormatVersion()  

Get the SBS format version compatible with this version of the API.

Returns:The format version as a string
 static getSBSUpdaterVersion()  

Get the SBS updater version compatible with this version of the API.

Returns:The updater version as a string
 static getSubstanceDesignerInstallPath(*args, **kwargs)  
 getUrlAliasMgr()  

Get the url alias manager

Returns:a UrlAliasMgr
 resolveDependencies(aSBSDocument)  

This function must be called once the parsing of a .sbs is over, to allow all the registered objects to finalize their initialization. This function calls the callback of each registered object.

Parameters:aSBSDocument (SBSDocument) – The SBSDocument to finalize
 resolveDependency(aParentDocument, aSBSDependency)  

This function allows to set and eventually parse the referenced package of the given dependency.

Parameters:
  • aParentDocument (SBSDocument) – The SBSDocument which contains the dependency
  • aSBSDependency (SBSDependency) – The dependency to handle
Returns:

the package referenced by the dependency if found, as a SBSDocument, None otherwise

 static setAutomationToolkitInstallPath(automationToolkitInstallPath)  

Set the installation folder of Substance Automation Toolkit

Parameters:automationToolkitInstallPath (str) – the absolute path to Substance Automation Toolkit installation folder
 setDefaultPackagePath(defaultLibraryPath)  

Set the default package library path, which corresponds to the alias sbs://

 setMDLRootPaths(aPathList)  

setMDLRootPath(aPathList) Set the list of MDL root path

Parameters:aPathList (list of string) – The list of absolute paths to add as MDL root paths
 static setModuleRegisters()  
 static setSubstanceDesignerInstallPath(*args, **kwargs)  
 class context.ProjectMgr(aContext=None, aSbsPrjFilePath=None, aSBSProject=None)  

Bases: object

Class that manage the sbsprj (currently, readonly). For instance it’s usable to get params values i.e: aSbsPrj.getSettingsInfo().getVersion().getValue() Or populate the AliasUrlMgr with the alias’ sbsprj file. It is retrievable by a Context: aContext.getProjectMgr() a aSbsPrjFilePath file path can be pass as arg. Or as create an instance aPrjMgr = ProjectMgr() a aSbsPrjFilePath file path can be pass as arg. The context is also retrievable directly from aPrjMgr.

 getContext()  

get the Context class from ProjectMgr

Returns:
 getDependenciesPathStorageMethod(method='not_near_or_under')  

Shortcut in order to get the dependencies path storage method

Parameters:method – not_near_or_under or near_or_under
Returns:SBSPRJDependenciesPathStorageMethods
 getOcioConfigFilePath()  

Shortcut in order to get the config.ocio path

Returns:str
 getSBSProject()  

get the SBSProject class which containt the options

Returns:
 getUrlAliasMgr()  

get the SBSProject class which containt the options

Returns:
 parseADoc(aSbsPrjFilePath)  

Parse the sbsprj file in order to populate the ProjectMgr

Parameters:aSbsPrjFilePath – a sbsprj file
Returns:
 populateUrlAliasesMgr()  

Complete UrlAliasesMgr with the sbsprj’s aliases

Returns:
 setDependenciesPathStorageMethod(value, method='not_near_or_under')  

Shortcut in order to set the dependencies path storage method

Parameters:
  • method – sbsproject.SBSDependenciesPathTypes enum
  • value – sbsproject.SBSDependenciesPathMethods enum
Returns:

SBSPRJDependenciesPathStorageMethods

 setOcioConfigFilePath(value)  

Shortcut to set the config ocio file path and switch pref to custom

Parameters:value – str file path of config.ocio
 class context.UrlAliasMgr  

Bases: object

Class that contains Url Aliases information

 static buildTmpFolderPath(aFolderName)  

Build a temporary folder path in the Substance Automation Toolkit temporary directory, with the given folder name and a unique part (aFolderName_XXXXXX)

Parameters:aFolderName (str) – The name of the folder to create in the temporary directory
Returns:the directory path as a string
 convertToAliasedPath(aUrl)  

Tries to convert the given url with an aliased one. If the url starts with the absolute path of a registered alias, this part will be expressed using the alias. If no conversion possible, the url is returned as is.

Parameters:aUrl (str) – The absolute url to convert
Returns:The same url expressed with an alias if possible, or the url itself otherwise
 getAliasAbsPath(aAliasName)  

Get the absolute path associated to the given alias.

Parameters:aAliasName (str) – Name of the alias
Returns:The absolute path of this alias if found, None otherwise
 getAliasInPath(aUrl)  

Get the alias part in the given url, if this alias has been declared. For instance, if the url is in the format myalias://rest/of/the/path.ext, the function will return ‘myalias’ if this alias has been registered in the aliases dictionary.

Parameters:aUrl (str) – URL
Returns:The name of the alias if found, None otherwise
 getAllAliases(self, includeDefault=False)  

Get all aliases as a list of strings correctly formatted: alias://path/to/the/alias

Parameters:includeDefault (bool, optional) – True to include the default alias (sbs://). Default to False
Returns:a list of string
 static getTemporaryDirectoryPath()  

Get the temporary folder dedicated to Substance Automation Toolkit

Returns:The temporary folder as a string
 isUnderPath(aUrl, aDirAbsPath)  

Check if the aUrl path is by or below the aDirAbsPath. :param aUrl: The URL to convert to a relative path :param aDirAbsPath: The absolute directory path :type aUrl: str :type aDirAbsPath: str :return: True if under aDirAbsPath otherwise False

 static normalizePath(aPath)  

Return a correctly normalized path considering the running OS

Parameters:aPath (str) – The path to normalize
Returns:The normalized path as a string
 setAliasAbsPath(aAliasName, aAbsPath)  

Save the given alias into the alias dictionary.

Parameters:
  • aAliasName (str) – Name of the alias, without ‘://’.
  • aAbsPath (str) – Absolute directory of this alias
 toAbsPath(aUrl, aDirAbsPath)  

Convert the given url into an absolute path, considering the given absolute directory path. This means that if the url is relative, it will be considered as relative to the given directory path. If the url contains a registered alias, the alias part in the url will be replaced by the alias absolute path. If the url is already absolute, it will be only formatted correctly for the running platform.

Parameters:
  • aUrl (str) – The URL to convert to an absolute path
  • aDirAbsPath (str) – The absolute directory path
Returns:

The absolute path corresponding to the given url, correctly formatted for the running platform.

 toRelPath(aUrl, aDirAbsPath)  

Convert the given url into a relative path, relatively to the given directory absolute path. If the url is expressed using an alias, it will be returned as is. If the path of a registered alias is found in the url, it will be expressed with this alias.

Parameters:
  • aUrl (str) – The URL to convert to a relative path
  • aDirAbsPath (str) – The absolute directory path
Returns:

The relative path corresponding to the given url.

 urlToFilePath(aUrl)  

Convert an url type file:///tmp/afile.sbs to a path file /tmp/afile.sbs :param aUrl: The URL to convert to a relative path :return: a file path

 Adobe

Get help faster and easier

New user?