Notifications
Clear all

[Closed] SDK: Accessing MXS Struct members from C++ function?

Hi,

If I am to write a maxscript extension, in the form of an exposed C++ function, and I wanted this function to take a maxscript Struct as an argument, how would I go about reading the member data from it?

E.g. I have a function MyFunc, and a MaxScript struct: struct MyStruct ( member1 )

The signature for MyFunc would be as follows, in C++:
Value *MyFunc_cf(Value **arg_list, int count);

So if I say pass in an instance of MyStruct as the argument for MyFunc, how do I read the contents of MyStruct? Lets say I store the value of 5 inside MyStruct::member1, how do I extract it inside MyFunc_cf() ?

Also, how do i check the type of the argument passed so that it is indeed a struct, not an int for example? I tried:
type_check(arg_list[0], Struct, “Struct arg”);

But there is no Struct_class apparently. So what is the correct type I use?

It is a pain how half of these classes are not even documented…

7 Replies

Can you call normal functions from MaxScript so that it works fine?

I know the functions in the structs should behave exactly like normal functions (basically they have a function ID nbr), but haven’t tried calling that from c++ yet.

At worst you could yourself interprent the MaxScript text from C++ to check that it matches what you know to be correct MaxScript.

/Andreas

‘ExecuteMaxscriptCommand’ will allow you to run anything like your would normally do inside maxscript.

So:

FPValue retVal;
ExecuteMaxscriptCommand (“MyStruct.member1”, retVal);
Will return whatever is in member1 into retVal.

Doing a check to make sure the passed in value is a struct you would do via Superclass:
I.e. in maxscript:
superclassof myStruct
will return: StructDef
(In the SDK: ->SuperClassID)

I typed the above without verifying the exact names of stuff, it could be I missspelled a thing or two.

-Kees

Firstly thanks f97ao and kees for your help.

 Can you call normal functions from MaxScript so that it works fine?

Yes, that part was relatively straight forward. (despite the quirks of the macro abuse)

 'ExecuteMaxscriptCommand' will allow you to run anything like your would normally do inside maxscript.

That’s lovely. Where did you find that out? I checked both the index and search function of the MAX 9 SDK reference, and find no such function. Or maybe its a macro? You never know, i guess. (Hard to use a function without any information on it)

Doing a check to make sure the passed in value is a struct you would do via Superclass:
I.e. in maxscript:
superclassof myStruct
will return: StructDef

(In the SDK: ->SuperClassID)

Ok, is SuperClassID a method or property of the Value class? Since what I get passed into my exposed function is a Value ** and for some strange reason the Value class is undocumented also. Isn’t that lovely. Time to study the headers i guess…

The executeMaxscriptCommand I found in a header somewhere.
I think its not documented…but it works well.

-Kees

Oh its actually called: “ExecuteMAXScriptScript”
My bad…

-Kees

great, I love undocumented functions.

Anyhow, I’ve decided to take a different approach altogether. Inititally I was going to write my backend in C++, and the interface in MXS, but have decided to just implement the interfaces I’m given and write it all in C++.

Autodesk – please hire more staff for documenting the SDK.
…or better yet, rewrite/design it all together. C++ does have a standard now.

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

Yes more documentation for the SDK would be quite lovely. I had an enormous headache when I tried to figure out how the editable_poly objects works. Many of the functions didn’t have any description at all. However the manual is at least WAY better after max8 so there is definetly improvement. MaxScript is well documented, but the c++ SDK is scary.

/Andreas