Extending Python - Pass Variable Parameter?

On 09/08/2016 at 16:13, xxxxxxxx wrote:

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

---------
Howdy,

Is it possible to create a python extension function that takes an integer for the first parameter, and then a variable parameter for a second parameter, like I can do with a coffee extension function?

For instance if I want the first parameter to be an ID, and then the second parameter to be either a bool, integer or float. Is that possible?

Adios
Cactus Dan

On 09/08/2016 at 18:16, xxxxxxxx wrote:

Howdy,

OK, never mind. I took an educated guess and it worked perfectly:

LONG id;
GeData gdata;
  
const CHAR *kwlist[] = {"integer", "gedata", NULL};
if(!pylib.ParseTupleAndKeywords(args, keywords, "iG", kwlist, &id, &gdata)) return pylib.ReturnPyFALSE();
  
if(gdata.GetType() != DA_LONG && gdata.GetType() != DA_REAL) return pylib.ReturnPyFALSE();

The last line checks the type, so the function only accepts a bool, int or float (a bool is actually an int). 😉

Adios,
Cactus Dan

On 10/08/2016 at 02:31, xxxxxxxx wrote:

Hi,

Yes, using a GeData is the way to go in Python to parse a parameter that can be of various types.

On 10/08/2016 at 05:45, xxxxxxxx wrote:

Howdy,

Well, the educated guess was mainly in the use of the string "gedata". I sort of knew that a GeData was the way to go.

That's why I asked in the other thread if you could post a complete list of parameters for the different types. 😉

Adios,
Cactus Dan