On 31/01/2013 at 11:12, xxxxxxxx wrote:
Hello Robert,
I think at the point the object is read, the tags have not been read yet, although the links would
be valid. You can read them, but you have to evaluate them at a later time, for example at the
first message sent to your object after reading was done.
/**
* Copyright (C) 2013, Niklas Rosenstein
* You are allowed to use and/or modify this code for private or
* commercial use.
**/
#include <c4d.h>
#include <ge_dynamicarray.h>
class TestObject : public ObjectData {
public:
LONG count;
BaseLink** array;
static NodeData* Alloc() { return gNew TestObject; }
TestObject() : ObjectData(), array(NULL) {
}
~TestObject() {
if (array) {
for (LONG i=0; i < count; i++) {
BaseLink::Free(array[i]);
}
GeFree(array);
array = NULL;
}
}
// Overrides: ObjectData
Bool Message(GeListNode* node, LONG type, void* pData) {
if (!ObjectData::Message(node, type, pData)) return FALSE;
if (array) {
BaseDocument* doc = node->GetDocument();
GeDebugOut("%d BaseLinks were read in!", count, type);
for (LONG i=0; i < count; i++) {
BaseLink* link = array[i];
BaseTag* tag = (BaseTag* ) link->GetLink(doc);
BaseLink::Free(link);
if (tag) {
// Requires a DEBUG build!
GeDebugOut(" - " + tag->GetName());
}
else {
GeDebugOut(" - <NULL>");
}
}
GeFree(array);
array = NULL;
}
return TRUE;
}
Bool Read(GeListNode* node, HyperFile* hf, LONG level) {
if (!ObjectData::Read(node, hf, level)) return FALSE;
if (!hf->ReadLong(&count)) return FALSE;
if (array) {
GeFree(array);
}
array = (BaseLink** ) GeAlloc(sizeof(BaseLink** ) * count);
if (!array) return FALSE;
for (LONG i=0; i < count; i++) {
BaseLink* link = BaseLink::Alloc();
if (!link) return FALSE;
if (!link->Read(hf)) {
BaseLink::Free(link);
return FALSE;
}
array[i] = link;
}
return TRUE;
}
Bool Write(GeListNode* node, HyperFile* hf) {
if (!ObjectData::Write(node, hf)) return FALSE;
AutoAlloc<AtomArray> tags;
AutoAlloc<BaseLink> link;
if (!tags || !link) return FALSE;
// Fill the *tags* array with all tags on the host object.
BaseTag* tag = ((BaseObject* )node)->GetFirstTag();
while (tag) {
tags->Append(tag);
tag = tag->GetNext();
}
// Write the number of tags to the file.
LONG count = tags->GetCount();
if (!hf->WriteLong(count)) return FALSE;
// Write the tag-links to the file.
for (LONG i=0; i < count; i++) {
tag = (BaseTag* ) tags->GetIndex(i);
link->SetLink(tag);
link->Write(hf);
}
return TRUE;
}
};
Bool PluginStart() {
return RegisterObjectPlugin(
1000001, "BaseLink Writer", 0, TestObject::Alloc, "", NULL, 0);
}
Bool PluginMessage(LONG type, void* pData) {
return TRUE;
}
void PluginEnd() {
}
Best,
Niklas