@Cairyn said in Writing data to the .c4d file:
I suppose you mean saving data to the BaseContainer of the BaseDocument? You'll need a plugin id for that so it will not collide with the existing IDs, then you can put a sub-BaseContainer with your data into that container. Or you can define your own datatype.
Here's what I've got so far for the sub-BaseContainer. It doesn't seem to be working. Any ideas about what I'm doing incorrectly?
import c4d
PLUGIN_ID = 1234567
MyUniqueId = 1000001
def main():
doc = c4d.documents.GetActiveDocument()
#get the document's BaseContainer
bc = doc.GetDataInstance()
#create a sub-BaseContainer
subBc = c4d.BaseContainer()
subBc[1000] = "hello"
subBc[2000] = "world!"
#add the sub-BaseContainer to the document Base Container
bc.SetContainer(MyUniqueId, subBc)
#set the Document Data using the plugin ID
doc.SetDocumentData(PLUGIN_ID, bc)
c4d.EventAdd()
#get the sub containers data
print bc[PLUGIN_ID][2000]
if __name__=='__main__':
main()