- 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
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: |
|
---|---|
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: |
|
---|---|
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: |
|
---|---|
Returns: | the package referenced by the dependency if found, as a |
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: |
|
---|---|
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: |
|
---|
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: |
|
---|---|
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: |
|
---|---|
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