Extending Python - Default Parameters?

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

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


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?

Cactus Dan

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).

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


Thanks, Yannick. 😉

Cactus Dan