Exposing a Function to MAXScript

This topic is about manually exposing a function to MAXScript using the MAXScript API. Usually, a plug-in uses the function publishing system to expose functions to MAXScript. For more information see the section about Function Publishing.

Functions are exposed to MAXScript using the Primitive class (defined in maxscript\foundation\functions.h). A Primitive class exposes a function pointer to the MAXScript engine.

The standard practice for doing so is to use the def_visible_primitive macro, from the header file maxscript\macros\define_instantiation_functions.h as shown below:

#include <maxscript\macros\define_instantiation_functions.h>
def_visible_primitive(IntervalArray, "IntervalArray");

This expands during pre-processing to the following:

Value* IntervalArray_cf(Value**, int);
PrimitiveIntervalArray_pf("IntervalArray", IntervalArray_cf);

In this case you would next need to provide a function body for the function IntervalArray_cf(). For example:

#include <maxscript\maxscript.h>
#include <maxscript\macros\define_instantiation_functions.h>
def_visible_primitive(IntervalArray, "IntervalArray");
 
Value* IntervalArray_cf(Value **arg_list, int count)
{
   return &ok;
}