SDK - optional argument

SDK - optional argument

MehdiZangenehBar
Advocate Advocate
2,933 Views
9 Replies
Message 1 of 10

SDK - optional argument

MehdiZangenehBar
Advocate
Advocate

Ii want to expose a function with optional argument:

 

#include <maxscript/maxscript.h>
#include <maxscript/maxwrapper/mxsobjects.h>
#include <maxscript/macros/define_instantiation_functions.h>

// ==================================================

#undef def_name
#define    def_name(name)   Value* n_##name;

// ==================================================

def_name(option)

// ==================================================

def_visible_primitive(TestFunction, "TestFunction");
Value* TestFunction_cf(Value **arg_list, int count)
{
	// TestFunction <argA> <argB> [option:false]

	Value* tmp;
	int option = int_key_arg(option, tmp, 777);

	mprintf(L"%i\n", option);

	return &ok;
}
TestFunction option:55 -- any input will return 777

But it always return default value which means the option is &unsupplied.

 

0 Likes
2,934 Views
9 Replies
Replies (9)
Message 2 of 10

istan
Advisor
Advisor

What shows the "count" value?

0 Likes
Message 3 of 10

istan
Advisor
Advisor

I usually include always only the right <maxscript\macros\*.h> files and do not override any defines by my own. In your case, the def_name() define is somehow different. I can't tell if it makes a difference.

0 Likes
Message 4 of 10

MehdiZangenehBar
Advocate
Advocate

count return 3

0 Likes
Message 5 of 10

MehdiZangenehBar
Advocate
Advocate

I got this error when I want to include macros:

Error    C1083    Cannot open include file: 'ClassCfg.h': No such file or directory

Would you please test the code in your project?

0 Likes
Message 6 of 10

istan
Advisor
Advisor

I already use similar code in hundreds of functions. For me it works and I did not see an obvious bug in yours - except your define. I would rather make the project settings right and not override SDK defines. There are too many different settings which have to be considered in different places. I simply include always the right include file in the right place (sometimes even in the middle of the code).

0 Likes
Message 7 of 10

MehdiZangenehBar
Advocate
Advocate

I just create a GUP with wizard, You don't get error 'ClassCfg.h' when you include macros?

0 Likes
Message 8 of 10

istan
Advisor
Advisor

No, I don't get such an include error - but I also never ever used any AD project wizard (as they are/were always erroneous). For keeping my code base together for the different Max Versions, I of course use my own prop sheets.

Compiler errors on missing include files: check the include paths..

Linker errors on missing functions: check the lib paths..

0 Likes
Message 9 of 10

MehdiZangenehBar
Advocate
Advocate

I don't think it's because of project settings. When I use a name predefined in the corenames.inl, everything works fine, But when I define mine, not working.

0 Likes
Message 10 of 10

istan
Advisor
Advisor

i.e. you included or defined something different (wrong), before you use def_name()

0 Likes