Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    BaseFile

    Scheduled Pinned Locked Moved SDK Help
    4 Posts 0 Posters 279 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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);
      }

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 06/09/2009 at 02:06, xxxxxxxx wrote:

        Hi I've found the problem (I should have left return off "if(!file->WriteString("hallo", GE_7BIT)) return;" It's working fine now. Is there a newline function in that can be used with WriteString?
        Regards Conor

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 06/09/2009 at 11:26, xxxxxxxx wrote:

          C/C++/Java/COFFEE/etc.: newline '\n' character. This type of notation (with the \) is called an 'escape character' or 'escape sequence'. With it you can do things like (tab), \\ (actually print \), \0value (an ASCII/UniCode value, number). Do a Google search for 'escape sequence' and you'll get many links to lists of and information on them. 🙂

          file->WriteString("Hallo\n", GE_7BIT);

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 06/09/2009 at 11:40, xxxxxxxx wrote:

            Thanks very much Robert, that's working great now.
            Cheers Conor

            1 Reply Last reply Reply Quote 0
            • First post
              Last post