I want to store the node to be hidden in the scene file, so I guess hf wil not work for me.
In the other thread I learned to use IsolateObjects and that works now.
So now I have a new doc in memory with the node I wanted to store.
I tried to put it in a subcontainer, but that did not work.
When reading back I just got None.
import c4d
PLUGIN_ID = 1234567
MyUniqueId = 456789
def main():
#retrieves the document baseContainer
docBC = doc.GetDataInstance()
sel = doc.GetSelection() # !!! only select the parent, not the children
newDoc = c4d.documents.IsolateObjects(doc, sel)
#create a sub-BaseContainer
subBc = c4d.BaseContainer()
subBc[1000] = "hello"
subBc[2000] = newDoc
# Add the container to the "main" Container
docBC.SetContainer(MyUniqueId, subBc)
# Updates the document container
doc.SetData(docBC)
# Print the values stored in our container.
for cid, value in doc.GetDataInstance().GetContainer(MyUniqueId):
print cid, value
# Print Hello World
print doc[MyUniqueId][1000], doc[MyUniqueId][2000]
if __name__=='__main__':
main()
Output:
1000 hello
2000 <c4d.documents.BaseDocument object called '' with ID 110059 at 0x00000173601BD370>
hello <c4d.documents.BaseDocument object called '' with ID 110059 at 0x00000173601BD330>
Reading back the container:
import c4d
PLUGIN_ID = 1234567
MyUniqueId = 456789
def main():
#retrieves the document baseContainer
docBC = doc.GetDataInstance()
# Print the values stored in our container.
for cid, value in doc.GetDataInstance().GetContainer(MyUniqueId):
print cid, value
# Print Hello World
print doc[MyUniqueId][1000], doc[MyUniqueId][2000]
if __name__=='__main__':
main()
Output:
1000 hello
2000 None
hello None