I have the following .PY code to load a .sbs (containing MDL material definition), and save it as MDL Preset.
Note the comments... if I save the package as MDL Module, it works (sExportPackage call). But I want to save as preset (sExportPreset) and it's throwing an exception. Perhaps I'm getting the SDMDLGraph incorrectly?
(sbsPathIn is a python Path variable to location of .sbs.)
def open_and_save_sbs_as_mdl(sbsPathIn):
mdlFilePath = str(sbsPathIn).replace(str(rootFolderOfSubstances), str(rootFolderOfOutputMDL)) #alternate directory for MDLs
mdlFile = mdlFilePath.replace('.sbs', '.mdl') # same filename but .mdl extension of course
ensure_dir(mdlFile) # make sure directories are created for mdl preset we want to save
pkg = sdPkgManager.loadUserPackage(str(sbsPathIn)) #get package
children = pkg.getChildrenResources(False) #get children
for child in children:
if (child.getClassName() == 'SDMDLGraph'):
#sdmdlexporter.SDMDLExporter.sExportPackage(pkg, mdlFile) # this works
sdmdlexporter.SDMDLExporter.sExportPreset(child, mdlFile) # this throws exception
else:
print('Error exporting MDL preset: ' + mdlFile)
sdPkgManager.unloadUserPackage(pkg)
Console output from execution:
[ERR][9]sdmdlexporter.SDMDLExporter.sExportPreset(child, mdlFile) # this throws exception:
[ERR][10] File "C:/Program Files/Allegorithmic/Substance Designer/resources/python\sd\api\mdl\sdmdlexporter.py", line 69, in sExportPreset
[ERR][11]
[ERR][12]raise APIException(SDApiError(_res))
[ERR][13]sd.api.apiexception
[ERR][14].
[ERR][15]APIException
[ERR][16]:
[ERR][17]SDApiError.Undefined
[MSG][18]Run finished.