User Guide Cancel

script_update_with_sbsupdater | Substance 3D Automation ToolKit

script_update_with_sbsupdater

script_update_with_sbsupdater.scriptUpdatePackagesVersion(aContext, aPreviousVersion, aPreviousUpdaterVersion, aPackagesFolderRootDir, aBatchToolsFolder=None)
script_update_with_sbsupdater.scriptUpdatePackagesVersion(aContext, aPreviousVersion, aPreviousUpdaterVersion, aPackagesFolderRootDir, aBatchToolsFolder=None)
script_update_with_sbsupdater.scriptUpdatePackagesVersion(aContext, aPreviousVersion, aPreviousUpdaterVersion, aPackagesFolderRootDir, aBatchToolsFolder=None)

Allows to update to the current version of Substance Designer all .sbs recursively included in the given folder path using the Mutator Batch Tool.

Parameters:
  • aContext (context.Context) – Execution context
  • aPreviousVersion (str) – Previous version number. Only .sbs with this version will be updated
  • aPreviousUpdaterVersion (str) – Previous updater version number. Only .sbs with this updater version will be updated
  • aPackagesFolderRootDir – The root folder containing the packages to update
  • aBatchToolsFolder (str, optional) – The folder containing the batch tools executables. If not provided, the path of Substance Designer identified by the given context will be used
Returns:

True if success

Here is the code of function scriptUpdatePackagesVersion:

aUpdaterPath = aContext.getBatchToolExePath(aBatchTool=sbsenum.BatchToolsEnum.UPDATER, aBatchToolsFolder=aBatchToolsFolder)
aPresetPackagePath = aContext.getDefaultPackagePath()
try:
aCommand = [aUpdaterPath, '--no-dependency', '--output-path', '{inputPath}', '--output-name', '{inputName}', '--presets-path', aPresetPackagePath]
log.info(aCommand)
aRootDir = os.path.normpath(aPackagesFolderRootDir)
for root, subFolders, files in os.walk(aRootDir):
for aFile in files:
if aFile.endswith('.sbs'):
aPackagePath = os.path.join(root, aFile)
aDoc = substance.SBSDocument(aContext=aContext, aFileAbsPath=aPackagePath)
log.info('Parse substance '+aPackagePath)
try:
aDoc.parseDoc()
except SBSIncompatibleVersionError:
pass
if aDoc.mFormatVersion == aPreviousVersion and aDoc.mUpdaterVersion == aPreviousUpdaterVersion:
aMutatorCmd = aCommand + ['--input', aPackagePath]
print(aMutatorCmd)
log.info('Update substance '+aPackagePath)
subprocess.check_call(aMutatorCmd)
log.info('=> All packages have been updated using the Mutator Batch Tool')
return True
except BaseException as error:
log.error("!!! [demoUpdatePackagesVersion] Failed to update a package")
raise error
aUpdaterPath = aContext.getBatchToolExePath(aBatchTool=sbsenum.BatchToolsEnum.UPDATER, aBatchToolsFolder=aBatchToolsFolder) aPresetPackagePath = aContext.getDefaultPackagePath() try: aCommand = [aUpdaterPath, '--no-dependency', '--output-path', '{inputPath}', '--output-name', '{inputName}', '--presets-path', aPresetPackagePath] log.info(aCommand) aRootDir = os.path.normpath(aPackagesFolderRootDir) for root, subFolders, files in os.walk(aRootDir): for aFile in files: if aFile.endswith('.sbs'): aPackagePath = os.path.join(root, aFile) aDoc = substance.SBSDocument(aContext=aContext, aFileAbsPath=aPackagePath) log.info('Parse substance '+aPackagePath) try: aDoc.parseDoc() except SBSIncompatibleVersionError: pass if aDoc.mFormatVersion == aPreviousVersion and aDoc.mUpdaterVersion == aPreviousUpdaterVersion: aMutatorCmd = aCommand + ['--input', aPackagePath] print(aMutatorCmd) log.info('Update substance '+aPackagePath) subprocess.check_call(aMutatorCmd) log.info('=> All packages have been updated using the Mutator Batch Tool') return True except BaseException as error: log.error("!!! [demoUpdatePackagesVersion] Failed to update a package") raise error
aUpdaterPath = aContext.getBatchToolExePath(aBatchTool=sbsenum.BatchToolsEnum.UPDATER, aBatchToolsFolder=aBatchToolsFolder) 
aPresetPackagePath = aContext.getDefaultPackagePath() 
try: 
    aCommand = [aUpdaterPath, '--no-dependency', '--output-path', '{inputPath}', '--output-name', '{inputName}', '--presets-path', aPresetPackagePath] 
    log.info(aCommand) 
 
    aRootDir = os.path.normpath(aPackagesFolderRootDir) 
 
    for root, subFolders, files in os.walk(aRootDir): 
        for aFile in files: 
            if aFile.endswith('.sbs'): 
                aPackagePath = os.path.join(root, aFile) 
                aDoc = substance.SBSDocument(aContext=aContext, aFileAbsPath=aPackagePath) 
                log.info('Parse substance '+aPackagePath) 
                try: 
                    aDoc.parseDoc() 
                except SBSIncompatibleVersionError: 
                    pass 
 
                if aDoc.mFormatVersion == aPreviousVersion and aDoc.mUpdaterVersion == aPreviousUpdaterVersion: 
                    aMutatorCmd = aCommand + ['--input', aPackagePath] 
                    print(aMutatorCmd) 
                    log.info('Update substance '+aPackagePath) 
                    subprocess.check_call(aMutatorCmd) 
 
    log.info('=> All packages have been updated using the Mutator Batch Tool') 
    return True 
 
except BaseException as error: 
    log.error("!!! [demoUpdatePackagesVersion] Failed to update a package") 
    raise error

Get help faster and easier

New user?