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
    11 Posts 0 Posters 931 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 07/01/2011 at 03:52, xxxxxxxx wrote:

      What is it you are trying to achieve?

      BaseFile is just that, a file where you can write certain basic values to. There is no automatic format involved, neither C4D's file format nor any other. If you want to produce a certain format (like, say, Maya 2011 or Lightwave CORE 2010 or Sculptris or PTex), you will have to write that functionality from the bottom up (since C4D cannot know any details about your format). That includes writing every vector, every polygon, and every object yourself in the exact way the target application expects it.

      Naturally, C4D will not be able to read that file either without your help. You will need to provide both the writing and reading functionality for your desired format.

      If you just want to save something so C4D can load it again, use the provided file functions from the menus (saving a scene, saving a bitmap, saving selected objects, saving materials, saving points as ASCII...) or their SDK equivalents. That way you don't have to use BaseFile at all and stay on a high abstraction level.

      If you want to add your own data to a document so this data will be saved with the document, use a BaseContainer within the scene to store the data; it will be saved and loaded automatically. If that data needs to represent a structure that is difficult to implement with a BaseContainer, use a custom data type (where you need to write and read the data with your own dedicated functionality to/from a HyperFile which is similar to a BaseFile).

      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 07/01/2011 at 05:03, xxxxxxxx wrote:

        I am trying to write a utility plugin that saves all of the data from a Model I have made in Cinema 4D to a file.  I do not want it to save to a .c4d file because I only want my plugin to be able to read this file.  Then, in another plugin I am working on,  I want the model that is saved, to be loaded back in to Cinema 4D so that my plugin can then manipulate the geometry.

        I have been looking at SaveDocument() but that doesn't seem to save any document to the filename that I specify.

        I will look around here at the cafe to see if there is sample code of how to save object information to a file.  Specifically polygon object information.

        ~Shawn

        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 07/01/2011 at 06:00, xxxxxxxx wrote:

          You might want to look into HyperFile - that saves some more complex data types, like BaseContainer, BaseBitmap, or Matrix. No BaseObject though, as far as I can see... haven't used HyperFile myself outside of custom data types yet.

          SaveDocument() should work, you could IsolateObjects() first to save only a subset of the current scene. Can you provide the code that calls SaveDocument()? (This will write a C4D file however.)

          If you really need a proprietary file format for your data exchange, you will need to build it yourself (because you are the one who defines the format). If all you need is geometry, this shouldn't be too hard though.

          Keeping the format proprietary won't be enough though. If you really need secrecy, then you need to encrypt your output, so reverse engineering of your generated files will not enable any attacker to create a loader of his own (depending on the value of your data and the complexity of your format, this can be a temptation). If you don't really need proper security, then don't bother with proprietary formats.

          I'm still not sure what your usecase is and what problem you are trying to solve with proprietary loader/saver, but I guess there must be simpler ways to do it than that.

          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 07/01/2011 at 08:11, xxxxxxxx wrote:

            So this is what I am doing to write to the file.  I am slowly beginning to understand how it all works.    I may be way off base here but would anyone mind looking at this code and tell me if I am on the right track here.

              
            WriteFile(BaseDocument *doc, Filename filename){  
                
              //Declarations  
              //==================================================  
              AutoAlloc<BaseFile> file;  
              BaseObject *op = doc->GetActiveObject()->GetNext();  
              PolygonObject *objPoly = ToPoly(op);  
              Vector * points = objPoly->GetPointW();  
              CPolygon * polys = objPoly->GetPolygonW();  
              LONG polyCount = objPoly->GetPolygonCount();  
              LONG pointCount = objPoly->GetPointCount();  
              LLONG A, B, C, D;  
              
              //Open the BaseFile for writing.  
              file->Open(filename, FILEOPEN_WRITE, FILEDIALOG_IGNOREOPEN, BYTEORDER_INTEL, MACTYPE_CINEMA, MACCREATOR_CINEMA);  
              
              //Write the points of the active object to the file.  
              for (int i = 0; i < pointCount; i++){  
                  file->WriteLVector(points[i]);  
              }  
              
              //Write the polygons of the active object to the file.  
              for (int i = 0; i < polyCount; i++){  
                  A = polys[i].a;  
                  B = polys[i].b;  
                  C = polys[i].c;  
                  D = polys[i].d;  
              
                  file->WriteLLong(A);  
                  file->WriteLLong(B);  
                  file->WriteLLong(C);  
                  file->WriteLLong(D);  
              }  
              return TRUE;  
            }  
              
            

            The next thing I need do is figure out how to read this file and put the object back together in the other plugin.   I am sure there are key elements that I am missing .  If anyone sees anything that I am doing very wrong please help me out.

            Thanks so much.

            ~Shawn

            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 07/01/2011 at 09:10, xxxxxxxx wrote:

              At first glance: You will want to write polyCount and pointCount as first values in the file, so your reading method will be able to determine how many elements to read from the file.

              And as long as you don't actually write to the point and poly vectors, you can use the "R" versions of the getters.

              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 07/01/2011 at 10:01, xxxxxxxx wrote:

                Thanks Cairyn,

                I appreciate you taking the time to help me.  Do I need to write anything else besides the counters, points, and polygons?

                And, when I go to read this file, how do I piece it back together in to a polygon object?

                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 07/01/2011 at 10:18, xxxxxxxx wrote:

                  What you want to save totally depend on what you need later on... I would at least store the global matrix, so you will have position, rotation etc. later on. But in theory you can also store line color, x-ray flag, whatever is in the BaseContainer of the object... you can store the tag content like point/poly selections, and so on. What do you need? What does your "other plugin" operate on?

                  If all you want is the points and polygons, you already have your storage method.

                  As for reading it again: create a new, empty polygon object and fill its point and poly arrays with what you have saved. Same logic, it's easy.

                  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 07/01/2011 at 12:49, xxxxxxxx wrote:

                    I simply want to recreate a model with my other plugin.  It is sort of a preset in my plugin.  I want the plugin to create models I have already made and saved in my file.

                    I am confused about filling the point and poly arrays with the information I read from the file because all of the read functions return a Bool Type.  Do you have an example of reading the matrix information from the file?  How would I put the matrix in the file in the the matrix of a polygon object that I have created.

                    I tried this.

                      
                    LMatrix m;  
                      
                      //Open the BaseFile for reading.  
                      file->Open(filename, FILEOPEN_READ, FILEDIALOG_IGNOREOPEN, BYTEORDER_INTEL, MACTYPE_CINEMA, MACCREATOR_CINEMA);  
                        
                      objPoly->SetMg(file->ReadLMatrix(&m));  
                    

                    the problem is,  I get an error because SetMg() wants a Matrix,  but ReadLMatrix()  returns a bool. .

                    Any thoughts about this?

                    Thanks,

                    Shawn

                    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 07/01/2011 at 15:39, xxxxxxxx wrote:

                      Okay so here's what I worked out through looking through the SDK for my function for reading from the file,   but now the plugin is crashing.  Does anyone see any reason why this would crash?

                        
                      //READ FILE  
                      //===========================================//  
                      Bool ReadFile(BaseDocument *doc, BaseObject *op, Filename filename){  
                          
                        //Declarations  
                        //==================================================//  
                        AutoAlloc<BaseFile> file;  
                        LLONG polyCount;  
                        LLONG pointCount;  
                        LMatrix m;  
                        
                        //Open the BaseFile for reading.  
                        file->Open(filename, FILEOPEN_READ, FILEDIALOG_IGNOREOPEN, BYTEORDER_INTEL, MACTYPE_CINEMA, MACCREATOR_CINEMA);  
                          
                        file->ReadLMatrix(&m);  
                        file->ReadLLong(&polyCount);  
                        file->ReadLLong(&pointCount);  
                        
                        //Declarations  
                        PolygonObject *objPoly = PolygonObject::Alloc(pointCount, polyCount);   
                        CPolygon * polys = objPoly->GetPolygonW();  
                        LVector * points = objPoly->GetPointW();  
                          
                        for (int i = 0; i < pointCount; i++){  
                              
                            file->ReadLVector(&points[i]);  
                        }  
                        
                        for (int i = 0; i < polyCount; i++){  
                          
                            LLONG A = polys[i].a;  
                            LLONG B = polys[i].b;  
                            LLONG C = polys[i].c;  
                            LLONG D = polys[i].d;  
                              
                            file->ReadLLong(&A);  
                            file->ReadLLong(&B);  
                            file->ReadLLong(&C);  
                            file->ReadLLong(&D);  
                          
                        }  
                        
                        objPoly->SetMg(m);  
                        doc->InsertObject(objPoly, NULL, NULL, 0);  
                        
                        return TRUE;  
                      }  
                      
                      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 07/01/2011 at 16:00, xxxxxxxx wrote:

                        Crashes where? I recommend using a debugger for all programming issues. Observe the point of crash, set breakpoints, follow the values of local variables... obviously, I cannot debug your code for you, and in case of crashes it's essential to watch out for minute details.

                        But here's what's obviously wrong: in the polygon loop, you read the point indices from the polygon, then you read the data from the file and do nothing with that read data. Naturally, you must first read from the file, and then write the vertex indices to the polygon.

                        This shouldn't lead to a crash though, just to a polygon object with "null" polygons.

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