On 01/08/2018 at 09:00, xxxxxxxx wrote:
Hi guys, first time here !
I do not know much about C4D at all (barely use it) but I need to integrate some of our tools in it.
I am looking to insert custom data in the document, lets say FileId = 1 for example. Is there any way to do it ? I've looked through the docs and looked for info but it's pretty blurry how your supposed to do that, or if you even can. There seems to be a BaseContainer of some sort in the document, but I have no idea how to add arbitrary values to it.
On 02/08/2018 at 06:11, xxxxxxxx wrote:
Hi Tuft, first of all, welcome in the PluginCafe forum!
BaseDocument, like Objects, tag and pretty much everything a user can find in C4D inherit from BaseList2D, as you already found get a BaseContainer.
A BaseContainer is a kind of array (or a dictionary in python), where data are stored according to a given ID.
The benefice of BaseContainer, is all data stored within are part of the BaseList2D (so the object, tag, document) and they are automatically saved, read when you save/load a file.
For more information, you can read the C++ manual about BaseContainer.
Now regarding your question, you can easily add data to the BaseContainer of the document.
Since you don't want to override your parameter or other plugins to override your entry, you should get a unique ID here.
Now you can do something like that
YourUniqueId = 1000001
# Get an Instance of the BaseContainer (that mean all changes are directly made in the document)
bc = doc.GetDataInstance()
bc[YourUniqueId] = 10 # Set the value
print bc[YourUniqueId] # Read the value
If you have more than one value it's recommended to create a BaseContainer with all your data and then store this BaseCcontainer within the BaseContainer of the document with your unique ID.
The BaseContainer principle applies to everything, but if you want to attach data to a specific object, you can also create a Tag, depending on your need, but please let me know if you have any questions!
On 07/08/2018 at 10:02, xxxxxxxx wrote:
Thank you very much MaximeA ! That got me in the right direction ! I actually didn't realize there was a project object in C4D. When i got that i was able to add UserData to it, and it works like a charm.