How to save / load presets the C4D way



  • On 28/06/2013 at 15:24, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R13-R14 
    Platform:      
    Language(s) :

    ---------
    Hi, if you add a C-Motion to your project, you will find two buttons under the Basic tab:
    Load preset.. and Save preset..
    I would like to implement these in my custom tag, if possible at all.
    Having searched high and low, googled and bing-ed and read the docs and searched this and other forums, it seems that reading from file and saving to file is not much discussed.

    I CAN use an ordinary filesave dialog or the like. But I am much more interested in a function similar to the one mentioned in the C-Motion.
    And code examples would be very much welcome!



  • On 28/06/2013 at 17:07, xxxxxxxx wrote:

    You can load/save descriptions and other settings using the World Plugin Container.  Check SetWorldPluginData() and GetWorldPluginData() in the API docs.  For specific presets, just put the settings in a container with a name and maybe an element noting that it is a preset and save that container (BaseContainer) as above.

    Bool MyPlugin::Init(GeListNode* node)  
    {  
      BaseContainer*    bc =    static_cast<BaseTag*>(node)->GetDataInstance();  
      // Get stored settings  
      BaseContainer*    pbc =    GetWorldPluginData(ID_MYPLUGIN);  
      if (!pbc)                return TRUE;  
      bc->SetLong(MYPLUGIN_MODE,    pbc->GetLong(MYPLUGIN_MODE, MYPLUGIN_MODE_CIRCLE));  
      bc->SetVector(MYPLUGIN_COLOR,    pbc->GetVector(MYPLUGIN_COLOR, Vector(1.0,1.0,0.0)));  
      bc->SetLong(MYPLUGIN_RADIUS,    pbc->GetLong(MYPLUGIN_RADIUS, 20L));  
      bc->SetLong(MYPLUGIN_RECT_W,    pbc->GetLong(MYPLUGIN_RECT_W, 20L));  
      bc->SetLong(MYPLUGIN_RECT_H,    pbc->GetLong(MYPLUGIN_RECT_H, 20L));  
      
      return TRUE;  
    }  
    void MyPlugin::Free(GeListNode* node)  
    {  
      BaseContainer*    bc =    static_cast<BaseTag*>(node)->GetDataInstance();  
      // Store settings  
      BaseContainer    pbc;  
      pbc.SetLong(MYPLUGIN_MODE,        bc->GetLong(MYPLUGIN_MODE));  
      pbc.SetVector(MYPLUGIN_COLOR,   bc->GetVector(MYPLUGIN_COLOR));  
      pbc.SetLong(MYPLUGIN_RADIUS,    bc->GetLong(MYPLUGIN_RADIUS));  
      pbc.SetLong(MYPLUGIN_RECT_W,    bc->GetLong(MYPLUGIN_RECT_W));  
      pbc.SetLong(MYPLUGIN_RECT_H,    bc->GetLong(MYPLUGIN_RECT_H));  
      SetWorldPluginData(ID_MYPLUGIN, pbc);  
    }
    


  • On 28/06/2013 at 23:46, xxxxxxxx wrote:

    Thanks a lot for this, absolutely essential for me when writing plugins.
    Although, it is not actually what I am asking for, though.

    What I want, is for the user to being able to load and store the current settings as a preset using the dialog that C-Motion uses:

    I do not know at all how to invoke and use such a dialog. If at all possible.
    And by the way, the data I want to store is complicated, it is not as easy as a couple of description values.



  • On 29/06/2013 at 00:08, xxxxxxxx wrote:

    It is just a custom GeDialog. There is nothing like a preset dialog in c4d, you will have to build
    your own. In c4d_file you can find FileSelect() which will open the OS specific file selection
    dialog.



  • On 29/06/2013 at 00:23, xxxxxxxx wrote:

    Aha! I understand. So I'll have to make a GeDialog then, and use it form inside my tag plugin?!?



  • On 29/06/2013 at 00:29, xxxxxxxx wrote:

    You can have a button to save a named preset.  Again, you want to open a GeDialog with a text entry element (and Ok/Cancel).

    You can have a button to load a saved preset.  You can get the world plugin data, get the BaseContainers that each represent the presets. Open a GeDialog and use that list to fill a listview or a combo or whatever for the user to select a preset.


Log in to reply