metaprogrammingmaxscript

How to get arguments list for a MAXScript function


A quote from Autodesk 3DS MAX documentation:

When you use something like 'fn test val = ...", a MAXScriptFunction value is created and stored in variable test. If variable test was passed into another method, for example as a filter function, that method would test the class of the value to make sure it's a MAXScriptFunction and then call it using apply().

My question: The functions in 3DS MAX are stored in variables, like any other values. You can store them in arrays, pass them to other functions, do what ever you do with any other value. So the question is: is there any way to get the list of arguments the function expects, from the function variable?

Here goes a small exlplanation, to explain why I'm asking this question.

Let's say I have a large functions library, stored in structs. For example, one of those structs is called "ModelingTools"

Struct ModelingTools
(
    fn tool1 arg1 agr2 arg3 = (...),
    fn tool2 arg1 agr2 arg3 = (...),
    ...
)

ModelingTools = ModelingTools() --make an istance of the struct in global scope

And then I want to use those functions in other scripts. I write this:

ModelingTools.tool1 arg1 arg2 arg3 

And what if there are already tonns of those structs and tonns of functions inside them? The build-in editor doesn't have any autocomplete like Visual Studio or QT. So I decided to invent my own bicycle. Gladly, MAXScript has a build-in method to list all registered global values in MAX: globalVars.gather(). For structs defenitions it event prints all their members. I'm almost happy with this: now I can quick search throug all registered MAX structs, click on one of them in a list view and list all their member functions, quickly copy-paste the desired function call to my code.

The only problem is with the arguments. How do I know whitch arguments do I need to provide to a specific function?


Solution

  • Unfortunately, there is no MAXScript way to get function argument information from a function definition. I may be wrong (and would gladly be corrected), but there may not be an SDK way of getting said information, either.

    As there is no programmatical way of getting this information, you would have to invent your own, if you need it to be accessed by code. Such as meticulously cataloging and storing this additional metadata in a structure which mirrors the functional one.


    I've encountered a similar situation to what you describe: many libraries organized into structs. What worked well in our case was a manual solution: writing detailed function documentation as comments right above where our functions are defined. The trick is: if the function or a struct method is defined in a maxscript file, you can call showSource <functionVariable> to open the editor at the line of code where the function is defined. You instantly see the documentation.

    However, this does not help with functions defined in C++, or otherwise code that is not yours.