THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/09/2009 at 08:17, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10.5
Platform: Mac OSX ;
Language(s) : C.O.F.F.E.E ;
---------
Hi
I've been having trouble getting basefile to work, I've been copying the example from the sdk
// Creates a filename that points to "foo.txt" in the plugin's directory
var filename = GeGetRootFilename();
filename->RemoveLast();
filename->Add("foo.txt");
// Creates the file and writes a string to it
var file = new(BaseFile);
file->Open(filename, GE_WRITE);
file->WriteString("Hello World!");
into the the <MyMenuPlugin::Execute(doc)> part of the "hello world 2" example along with some other code that extracts user data from each frame. The other code runs but nothing seems to happen with the new Basefile part. I also tried Matthias's
var fn = new(Filename);
if(!fn) return;
if(!fn->FileSelect("Create file", TRUE)) return;
var file = new(basefile);
if(!file) return;
if(!file->Open(fn, GE_WRITE, FILE_IGNOREOPEN, GE_INTEL)) return;
if(!file->WriteString("hallo", GE_7BIT)) return;
but I get an empty txt. file. I'm struggling to come up with something new to try.
Any help would be much appreciated.
Kind regards
Conor
I've attached the full code as well.
// be sure to use a unique ID obtained from www.plugincafe.com
var PLUGIN_ID = 910002;
// be sure to use a unique ID obtained from www.plugincafe.com
// make a dialog class
class MyDialog : GeModalDialog
{
public:
MyDialog();
CreateLayout();
}
MyDialog::MyDialog() { super(); }
MyDialog::CreateLayout()
{
SetTitle("Hello World");
AddStaticText(4000,BFH_FIT,0,0,"Text Exporter",BORDER_THIN_IN);
AddDlgGroup(DR_DLGGROUP_OK|DR_DLGGROUP_CANCEL);
return TRUE;
}
// register plugin in menu
class MyMenuPlugin : MenuPlugin
{
public:
MyMenuPlugin();
GetID();
GetName();
GetHelp();
Execute(doc);
}
MyMenuPlugin::MyMenuPlugin() { super(); }
MyMenuPlugin::GetID() { return PLUGIN_ID; }
MyMenuPlugin::GetName() { return "Hello World"; }
MyMenuPlugin::GetHelp() { return "Demonstrates a simple modal dialog";
}
MyMenuPlugin::Execute(doc)
{
var d = new(MyDialog);
d->Open(-1,-1);
var t = doc->GetTime();
var sec = t->GetSecond();
var frame =int( t->GetFrame(doc->GetFps()));
var max_time = doc->GetMaxTime();
var max_sec = max_time->GetSecond();
var max_frame =(int(max_time->GetFrame(doc->GetFps())));
var fps = doc->GetFps();
var op = doc->FindObject("userdata");
var arr_1 = new(array,(max_frame+1));
var arr_2 = new(array,(max_frame+1));
var arr_3 = new(array,(max_frame+1));
var arr_4 = new(array,(max_frame+1));
var userStartTime = -1;
var userEndTime = max_frame;
var fps = doc->GetFps();
var bakeStartTime = GetActiveDocument()->GetTime(); //needed to initialize a BaseTime object
bakeStartTime->SetFrame(userStartTime, fps);
doc->SetTime(bakeStartTime); //set the time slider to the user's start time
var currentFrame = GetActiveDocument()->GetTime()->GetFrame(fps);
while(currentFrame < userEndTime)
{
StopAllThreads();
userStartTime++;
bakeStartTime->SetFrame(userStartTime, fps); //needed to convert frame to BaseTime
doc->SetTime(bakeStartTime);//SendPlayhead to next frame
var t = doc->GetTime();
var sec = t->GetSecond();
var frame =int( t->GetFrame(doc->GetFps()));
var redraw = DrawViews(DA_STATICBREAK);
EventAdd(EVENT_ANIMATE);
if(redraw == TRUE) currentFrame = GetActiveDocument()->GetTime()->GetFrame(fps);
arr_1[frame] = (op#ID_USERDATA:1);
arr_2[frame] = (op#ID_USERDATA:2);
arr_3[frame] = (op#ID_USERDATA:3);
arr_4[frame] = (op#ID_USERDATA:4);
}
var fn = new(Filename);
if(!fn) return;
if(!fn->FileSelect("Create file", TRUE)) return;
var file = new(BaseFile);
if(!file) return;
fn->SetSuffix("txt");
if(!file->Open(fn, GE_WRITE, FILE_IGNOREOPEN, GE_INTEL)) return;
var i = 0;
for(i=0;i <=userEndTime;i++)
{
println(i);
println(arr_1 _);
println(arr_2 _);
println(arr_3 _);
println(arr_4 _);
}
if(!file- >WriteString("hallo", GE_7BIT)) return;
file->Close();
println("Ready");
}
main()
{
Register(MyMenuPlugin);
}