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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Extending Python - Default Parameters?

    SDK Help
    0
    3
    273
    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
      Helper
      last edited by

      On 19/08/2016 at 05:23, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R13+ 
      Platform:   Windows  ; Mac  ;  Mac OSX  ; 
      Language(s) :     C++  ;   PYTHON  ;

      ---------
      Howdy,

      Can I create a function that has default parameters, so that the user can either pass that parameter or not and let the function use a default value?

      In extending COFFEE, I can test the value of the integer parameter "argc" to see how many parameters were passed. But, it looks like for extending python, only pointers are passed, and in the examples you posted, the "args" parameter is simply being forwarded to the ParseTupleAndKeywords() function. Does that parameter point to an argument count?

      Adios,
      Cactus Dan

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

        On 19/08/2016 at 05:48, xxxxxxxx wrote:

        Hi Dan,

        In the format string for ParseTupleAndKeywords() use the character '|' to mark the beginning of the optional parameters. For instance:

        String str;
        Int32 integer = 0;
        Float real = 0.0f;
          
        const Char *kwlist[] = {"str", "integer", "real", nullptr};
        if (!pylib.ParseTupleAndKeywords(args, keywords, "$|if", kwlist, &str, &integer, &real))
          return nullptr;
        

        If "integer" and "real" are not passed then their default value will be the one set at their initialization (0 and 0.0f).

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

          On 19/08/2016 at 06:03, xxxxxxxx wrote:

          Howdy,

          Thanks, Yannick. 😉

          Adios,
          Cactus Dan

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