Author Topic: Error on sbs.writeDoc  (Read 503 times)

One of the sbs files that I am writing automation code for throws an error when I attempt to save it.  I have reduced my code to simply opening & saving the file and the error persists, implying something is wrong with the sbs file.

For example, running this:
Code: [Select]
sbsDoc = substance.SBSDocument(aContext, sbsfile)
sbsDoc.parseDoc()
sbsDoc.writeDoc()

Results in a 160+ line traceback error that loops through the same 4 modules in pysbs.  Below is the end of it.  ([toolsdir] does not appear in the traceback, that is my edit)

Code: [Select]
  File "[toolsdir]\python\3.7\Lib\site-packages\pysbs\sbscommon\values.py", line 625, in write
    aSBSWriter.writeSBSNode(aXmlNode, element, 'treelist')
  File "[toolsdir]\python\3.7\Lib\site-packages\pysbs\api_decorators.py", line 54, in wrapper
    return function(*args, **kwargs)
  File "[toolsdir]\python\3.7\Lib\site-packages\pysbs\sbswriter.py", line 90, in writeSBSNode
    aSBSObject.write(self, aNewNode)
  File "[toolsdir]\python\3.7\Lib\site-packages\pysbs\api_decorators.py", line 54, in wrapper
    return function(*args, **kwargs)
  File "[toolsdir]\python\3.7\Lib\site-packages\pysbs\sbscommon\values.py", line 569, in write
    for element in self.mElements:
TypeError: 'NoneType' object is not iterable

It's like the class SBSTreelist in values.py gets handed a bunch of empty data and cannot handle it.

As I mentioned I think something is wrong with the sbs, but I'm unsure what to look at.  What's stranger is that running the command line tools, such as sbsmutator, have no problem editing the file.  It's just pysbs that has an issue.  Any advice or wild guesses are appreciated!

Adding to this, it's clearly because of the linked meshes in the file.

Problem persists if I delete all graphs from the sbs and run the code.  If I instead delete all linked mesh resources, I can write out the doc.

I went through all of the meshes and deleted all of them, one by one, until I was able to write the doc out again.  Every one of the 29 linked meshes causes the problem, except one.  There is a single mesh that can stay in the file and then sbs.writeDoc() can complete.

It seems to be the first mesh that was imported, if that says anything useful.  There other 28 are all variations of the same geo that the graph will be used with.

While I still don't know what was happening, I did get rid of the problem.

I deleted all the meshes from the sbs file, and had my script import & group them all in addition to its other operations. No more issues.

Something about the mesh resources was sour, though I am not sure what.  I also noticed that the order of the hierarchy in the explorer changed.  The 'Resources' group used to be at the top of the explorer within the sbs, but now is at the bottom. 

My wild guess is that during writeDoc() the xml tree was trying to create a node with a dependency that did not yet exist.  Odd that it only was an issue within pysbs, while sbsmutator and substance designer itself had no problem with it.

Hello!
Can you share with me which version do you use?
It looks like an old bug.