I try to save an object (using IsolateObjects()) using the Tag plugins Write() function.
Here the code:
class EDITABLECLEANTAG(plugins.TagData):
myData = None
def Write(self, node, HFfile):
print "WRITE myData: ", self.myData
# Store the size
HFfile.WriteInt32(self.myData[1])
# Store the data itself
if HFfile.WriteMemory(self.myData[0]) is False:
raise ValueError("can't write the file")
return True
def Message(self, tag, type, data):
doc = tag.GetDocument()
id = GetMessageID(data)
if id == CLICK_EDITABLECLEAN: # If this Gizmo is activated
# using a MemoryFileStructure to store a document
mfs = c4d.storage.MemoryFileStruct()
mfs.SetMemoryWriteMode()
IsolateObject = tag.GetObject()
print "IsolateObject: ", IsolateObject
newdoc = c4d.documents.IsolateObjects(doc , [IsolateObject])
# Save the document to the MemoryFileStructure
c4d.documents.SaveDocument(newdoc, mfs, c4d.SAVEDOCUMENTFLAGS_NONE, c4d.FORMAT_C4DEXPORT)
#Retrieve the data and store it somewhere, here in self.myData
self.myData = mfs.GetData()
print "Data saved: ", self.myData
When a button is clicked in the tag UI, I do an IsolateObjects(), and then store the resulting newdoc in myData.
Later on, when the scene file is saved, the Write() function is called automatically and the data is saved.
However, it looks to me that c4d.documents.SaveDocument() also calls Write().
If so, myData is not filled yet, and an error occurs.
What am I doing wrong?