On 08/01/2013 at 12:29, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;
---------
It's become painfully obvious to me over the past few days that I simply don't understand how HyperFile works regarding to saving data to a scene file.
There's plenty of examples in the forums about using HF like a BaseFile. And saving things to HD files. But not for using HF for saving data into the scene itself.
There is only one example in the SDK that uses HF like this. The RoundedTube example.
However...It doesn't seem to actually use the HF data ("test") it reads and writes. So that's teaches me nothing.
Trying to learn how HF works. I wrote this very basic tag plugin example that overrides the Read() & Write() methods to save and read a variable called "text" into a HF. But I have no idea what to do next.
#include "c4d.h"
#include "c4d_symbols.h"
#include "tsimpletag.h"
// be sure to use a unique ID obtained from www.plugincafe.com
#define PLUGIN_ID 1000010
class SimpleTag : public TagData
{
INSTANCEOF(SimpleTag,TagData)
public:
String text;
virtual Bool Read(GeListNode *node, HyperFile *hf, LONG level);
virtual Bool Write(GeListNode *node, HyperFile *hf);
virtual Bool Message(GeListNode *node, LONG type, void *t_data);
virtual Bool Init(GeListNode *node);
virtual EXECUTIONRESULT Execute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags);
static NodeData *Alloc(void) { return gNew SimpleTag; }
};
Bool SimpleTag::Read(GeListNode *node, HyperFile *hf, LONG level)
{
return hf->ReadString(&text);
}
Bool SimpleTag::Write(GeListNode *node, HyperFile *hf)
{
return hf->WriteString(text);
}
Bool SimpleTag::Message(GeListNode *node, LONG type, void *data)
{
BaseTag *tag = (BaseTag* )node; //Get the tag and assign it to a variable
BaseContainer *bc = ((BaseList2D* )node)->GetDataInstance(); //Get the container for the tag
switch (type)
{
case MSG_DESCRIPTION_COMMAND:
{
DescriptionCommand *dc = (DescriptionCommand* )data; // data contains the description ID of the button
LONG button = dc->id[0].id; // Get the ID of the button
switch (button)
{
case BUTTON1:
GePrint("Button1 was pushed");
break;
}
}
}
tag->SetDirty(DIRTYFLAGS_DATA); //Used to update a Tag's AM GUI items
return TRUE;
}
Bool SimpleTag::Init(GeListNode *node)
{
text = String("Hello");
return TRUE;
}
EXECUTIONRESULT SimpleTag::Execute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags)
{
BaseContainer *bc = tag->GetDataInstance();
return EXECUTIONRESULT_OK;
}
Bool RegisterSimpleTag(void)
{
String path = GeLoadString(IDS_SIMPLETAG); if (!path.Content()) return TRUE;
return RegisterTagPlugin(PLUGIN_ID,path,TAG_EXPRESSION|TAG_VISIBLE,SimpleTag::Alloc,"tsimpletag",AutoBitmap("myicon.tif"),0);
}
I don't know how to access and use the string data that I've just written into the HF.
If I have written this correctly. I should have a string with the value of "Hello" somewhere saved in the default HF of the scene right?
When I look in the tag with: BaseContainer *tagdata = tag->GetDataInstance();
When I look in the doc with: BaseContainer *docdata = doc->GetDataInstance();
I can't find it. And since I did not allocate a HF, I don't know where to find the HF this data has supposedly been saved to.
I'm completely lost how we're supposed to use HF in this manner.
-ScottA