Message 1 of 7
Using maxscript structs in sdk c++ code
Not applicable
01-21-2008
02:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Does anybody have any examples of working with Maxscript structs in an SDK c++ exposed function?
I need to be able to take a struct as a parameter to my c++ function, look at the parameter names (I'd rather not have to pre-assume they'll be defined names), process the data, and return a different struct with the results.
this now seems to be working, but I'd still welcome feedback in case I'm doing anything in a silly way
The key is pre-defining the parameter names using the def_name macros, rather than using strings
This is called from maxscript like so:
I need to be able to take a struct as a parameter to my c++ function, look at the parameter names (I'd rather not have to pre-assume they'll be defined names), process the data, and return a different struct with the results.
this now seems to be working, but I'd still welcome feedback in case I'm doing anything in a silly way
The key is pre-defining the parameter names using the def_name macros, rather than using strings
def_visible_primitive(SetStruct, "SetStruct");
// Initialise the parameter names we're using
#include <maxscrpt\lclinsfn.h>
def_name(param1)
def_name(param2)
// This is called from the Gup's Start() function
void InitParams()
{
// This creates the actual key vars
#include <maxscrpt\lclimpfn.h>
def_name(param1)
def_name(param2)
}
Value* TestStruct_cf(Value** arg_list, int count)
{
check_arg_count(TestStruct, 1, count);
Value* val = arg_list;
if( is_struct(val) )
{
Struct* myStruct = (Struct*)val;
// Assumes the passed in struct contains a key called "param1"
std::string strBlah = val->_get_property( n_param1 )->to_string();
}
else
{
throw UserThrownError("Parameter is not a maxscript struct!", TRUE);
}
return &true_value;
}
This is called from maxscript like so:
struct wibble ( param1, param2 )
doodads = wibble param1:"hello" param2:42
TestStruct doodads