Load Layout using CommandLineArgs? [SOLVED]



  • On 04/11/2014 at 11:10, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   13 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hi.
    I'm having trouble understanding how to use the C++ args to load a specific layout when C4D launches.

    Bool PluginMessage(LONG id, void *data)  
    {  
      switch (id)  
      {  
          case C4DPL_COMMANDLINEARGS:  
          {  
              C4DPL_CommandLineArgs *args = (C4DPL_CommandLineArgs* )data;  
             
              //Now What do I do?  
      
          }break;  
      }  
      
      return FALSE;  
    }
    

    -ScottA



  • On 04/11/2014 at 12:01, xxxxxxxx wrote:

    Hi Scott,
    not quite sure, if you are asking how to parse the command line args, or if you want to know, how to load a layout via command line.
    In the later case, there is already a commandline option to start with a specific layout:
    -layout yourlayout.l4d (including path)
    For example like so (in this case R13) :
    "CINEMA 4D 64 Bit.exe" -layout "C:\Users\Andreas\AppData\Roaming\MAXON\CINEMA 4D R13_05DFD2A0\library\layout\AB Modelling.l4d"

    In case you need to parse the args, let me know. Basically it works like parsing normal varargs (UNIX style).



  • On 04/11/2014 at 13:18, xxxxxxxx wrote:

    Hi Andreas.

    That works for me if I use it in the "target" option in my C4D icon. But it doesn't work in my main.cpp file. VS throws this error: identifier "layout" is undefined.
    If I put the entire thing inside of quotes. I get no errors. But it also doesn't load my layout when C4D starts either.

    I need to know how to do this from my main.cpp file.
    Something sort of like this?:

    args->argv[0] = "C:\Program Files\MAXON\CINEMA 4D R13\CINEMA 4D 64 Bit.exe" -layout "C:\Users\user\AppData\Roaming\MAXON\CINEMA 4D R13_05DFD2A0\library\layout\mylayout.l4d";
    

    I'm guessing that args is an array? But I cannot figure out how to use it properly.
    Every time I try to use it it crashes c4d.
    I can't figure out what args->argv needs to work properly without crashing.

    -ScottA



  • On 04/11/2014 at 13:28, xxxxxxxx wrote:

    You can't add commandline parameters there.
    All you can do, is parse the given args. And you are right argv is an array. argc provides you with the size of the array (depending on the number of arguments passed by the user). Then you can run over the array and do string comparisons for parameters and arguments. Just like varargs...This is from R15 SDK examples (in main.cpp) :

      case C4DPL_COMMANDLINEARGS:
        //sample implementation of command line rendering:
        //void CommandLineRendering(C4DPL_CommandLineArgs* args);
        //CommandLineRendering((C4DPL_CommandLineArgs* )data);
      
        //react to this message to react to command line arguments on startup
        {
          C4DPL_CommandLineArgs *args = (C4DPL_CommandLineArgs* )data;
          Int32 i;
      
          for (i=0;i<args->argc;i++)
          {
            if (!args->argv[i]) continue;
      
            if (!strcmp(args->argv[i],"--help") || !strcmp(args->argv[i],"-help"))
            {
              // do not clear the entry so that other plugins can make their output!!!
              GePrint("\x01-SDK is here :-)");
            }
            else if (!strcmp(args->argv[i],"-SDK"))
            {
              args->argv[i] = nullptr;
              GePrint("\x01-SDK executed:-)");
            }
            else if (!strcmp(args->argv[i],"-plugincrash"))
            {
              args->argv[i] = nullptr;
              *((Int32* )0) = 1234;
            }
          }
        }
        break;
    

    So the real question seems to be, how to load a layout from within your plugin, right?
    I need to learn it myself first. I'll keep you updated.



  • On 04/11/2014 at 13:45, xxxxxxxx wrote:

    While I'm looking for a way to load a layout, are you really sure you want to change the layout from within your plugin.
    I don't know what you are trying to achieve, but as a user, I'd jump with a part of body, where sun rarely shines, right into your face, if you changed my layout without my permission. Just saying... 😉 Can you be sure, the user saved his layout (if you are doing so while runtime)? Or if you want to change on startup, how is the user supposed to have his own startup layout?
    Wouldn't it be enough to deliver a layout with your plugin, the user can load, if he or she wants to?



  • On 04/11/2014 at 13:52, xxxxxxxx wrote:

    Haven't tried it yet, but couldn't you use SendCoreMessage() with COREMSG_CINEMA_EXECUTEEDITORCOMMAND to execute the "Load layout..." menu command?



  • On 04/11/2014 at 13:59, xxxxxxxx wrote:

    Oh. I see.
    People have posted in the past that to change the layout upon startup, we should use the CommandLineArgs. But they never really fully explain it. So I thought that's how we needed to do it.

    I figured out how to do it in the main.cpp using a different method:

            case C4DPL_PROGRAM_STARTED:  
              {                  
                  Filename fn = GeGetC4DPath(C4D_PATH_LIBRARY_USER) + "layout" + "\\" + "mylayout.l4d";            
                  LoadFile(fn);   
                  GePrint(fn.GetString());  
              }break;
    

    I would never do this in a public plugin. Where is forces the plugin to load a layout.
    But this might come in handy if I need to use it in a personal project. Possibly to swap layouts after a re-start.

    -ScottA



  • On 04/11/2014 at 14:13, xxxxxxxx wrote:

    Duh 😠
    Sometimes it can be so easy... LoadFile... thanks! I'll have the SDK docs changed.


Log in to reply