Exposing a Function to MAXScript
 
 
 

Note: This topic is about manually exposing a function to MAXScript using the MAXScript API. Most often a plug-in would use the function publishing system to expose functions to MAXScript. For more information see the section on Function Publishing.

Functions are exposed to MAXScript using the Primitive class (defined in maxscrpt/funcs.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 maxscrpt/funcs.h as shown below:

#include "definsfn.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 "MAXScrpt/MAXScrpt.h"
#include "MAXScrpt/definsfn.h"
def_visible_primitive(IntervalArray, "IntervalArray");
 
Value* IntervalArray_cf(Value **arg_list, int count)
{
   return &ok;
}

The following is a slightly more sophisticated example:

#include "MAXScrpt/MAXScrpt.h"
#include "MAXScrpt/MAXObj.h"
 
// The most important one.   Defines the correct flavor of dev_visible_primitive()
#include "MAXScrpt\definsfn.h"  
 
def_visible_primitive( MXS_VertexPaintTool, "VertexPaintTool");
Value* MXS_VertexPaintTool_cf(Value** arg_list, int count) {
       static MAXRefTarg thePaintboxValue( &thePaintbox );
       check_arg_count(MXS_DisplayVertexPaintTool, 0, count);
       return &thePaintboxValue;
}