[Closed] Get access to MaxScript Struct member in c++ function
Hi!
I’ve exposed a c++ function to maxscript. I’m doing it via def_visible_primitive macro. I’m passing a MaxScript struct as and argument to that function. Is there a way to get access to specific member of that struct?
Here is the C++ code:
def_visible_primitive(findPos, “UVP_findPos”);
Value* findPos_cf(Value *arg_list, int count)
{
check_arg_count(findPos, 1, count);
Value shell = arg_list[0];
if (!(is_structdef(shell)))
{
throw RuntimeError(_T(“Error! arg must be a struct!”));
}
//now I wana get a specific member of struct shell
return_value(shell);
}
and the sample MS code:
struct testStruct (member1 = 5)
UVP_findPos testStruct
Wana get acces to member1 in C++
Ok, I maybe passing structs isn’t very good idea, but let’s assume I pass an array, how to get acces to an element of the array? [] operator doesn’t seem to work…
Struct* str = (Struct*)value;
Value* val = str->_get_property(Name::intern(_M("member_name")));
whatever v = val->to_whatever()
Array* arr = (Array*)value;
Value* val = arr->data[i];
whatever v = val->to_whatever()
And another problem… debugger says something like “Information is unavailable, symbols for Maxcrpt.dll not loaded”, what can be done about it?
Is it possible to make a Void function visible to Max script? So it returns nothing? Just modifies an array, for example?
UPD: probably answered the question my self already. It can just return OK which is okClass derived from Value.
And how to convert some data type, like int or float, to value*? I’ve tried like this (Value*)&IntNumber but it gives memory access error…
different types have different methods but specifically for float and integer are Float::intern() and Integer::intern()
but it’s better to read the sdk help sometimes
there is an old rule: if you have tried all possible methods and still can not find a solution – look in the documentation
Thanks a lot! Yeah, the old RTFM rule, I know)) But in this case I didn’t know what exactly to search, what should be the search querry))
every time you have a sdk<->mxs question open avg_dlx.cpp and try to search any similar by what you do. the best way to find a sdk solution is look into sdk examples first and the sdk help next