@zipit Thanks for the explanation of the data structure (and the code for clarity).
I tried my best to get it working, but it's still not printing the data. I'm not sure if it was intentional, but I changed the line
print_container(doc.SetDocumentData(ID_MY_SECRET_COOKING_RECIPES))
as it was throwing an error for not passing a BaseContainer. Did you mean?
print_container(doc.GetDocumentData(ID_MY_SECRET_COOKING_RECIPES))
Regardless it's the same issue where it does see the BaseContainer in the print function, but cannot iterate through it.
import c4d
ID_MY_SECRET_COOKING_RECIPES = 2999999
ID_TITLE = 1008
ID_DATA = 1009
ID_INSTRUCTIONS = 1010
def print_container(bc):
for cid, value in bc:
print cid, value
if isinstance(value, c4d.BaseContainer):
print_container(value)
def main():
doc = c4d.documents.GetActiveDocument()
# Your settings container
bc = c4d.BaseContainer()
# One level of your container, we treat this like a list/folder
folder = c4d.BaseContainer()
# One item in your folder
recipe_1 = c4d.BaseContainer()
# Another item in your folder
recipe_2 = c4d.BaseContainer()
bc[ID_TITLE] = 'My Cooking recipes'
bc[ID_DATA] = folder
folder[1000] = recipe_1
folder[1001] = recipe_2
recipe_1[ID_TITLE] = 'Choclate delight'
recipe_1[ID_INSTRUCTIONS] = 'Lorem Ipsum ...'
recipe_2[ID_TITLE] = 'Cheesekake'
recipe_2[ID_INSTRUCTIONS] = 'Lorem Ipsum ...'
doc.SetDocumentData(ID_MY_SECRET_COOKING_RECIPES, bc)
print_container(doc.GetDocumentData(ID_MY_SECRET_COOKING_RECIPES))
if __name__=='__main__':
main()