Load/Save BaseLinkArray in Document
-
On 21/09/2017 at 16:44, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R16+
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;---------
I have a plugin Object which maintains an array of BaseLinks to tags (my plugin tags on other objects) in the scene document using a BaseLinkArray as a member of the ObjectData of the object plugin (instead of using GetDDescription() and dynamic LINKs). This is mainly for speed (avoid recursing the document) and to allow multiple of my plugin objects each with its own set of tags on objects.Is it possible to save a BaseLinkArray using Read/Write/Copyto (ala the BaseLink if must be)?
What would be the best practice (in code, please) to achieve this? Would GetDDescription() simply be about the same speed (realizing the slow down of using BaseLinks but with the advantage of having awareness of missing/deleted links).
-
On 22/09/2017 at 02:12, xxxxxxxx wrote:
Hello I don't have a working environment atm so I can't test but it should work.
In the Write override of your tag object, you iterate through your BaseLinkArray.
For each BaseLinks inside of your BaseLinkArray you create a HyperFile buffer.
You call BaseLinks::Write method with this HF.
Then you read the memory of this HF.
And you write inside the HF of the tag the size of this memory block and the memory itself.
In order to have a struct like this
Int32 SizeMemory
SizeMemory MemoryIn the Write override of your tag object.
For each MemoryBlock
Create an empty HyperFile buffer (make sure to flush it)
Past the MemoryBlock into tihs HF.
Alloc a new BaseLinks
Call BaseLinks::Read with the HF
Add this Baselinks to your BaseLinkArray -
On 22/09/2017 at 02:28, xxxxxxxx wrote:
Hello,
the best way to store internal data in a NodeData based plugin is to store that data in the object's BaseContainer. Then the data will automatically be copied and saved. See BaseContainer Manual.
BaseLinkArray is based on BaseArray, so you can use it the same way. E.g. to store it in a HyperFile you must store the number of elements and then each element of the array. See for example this code for reading and this code for writing an array. As gr4ph0s mentions a BaseLink can then be written to file or read from file using its I/O functions.
You should only worry about GetDDescription() if you want to display parameters in the Attribute Manager.
best wishes,
Sebastian