» Back to Documentation

Sometimes it is desirable to have a function defined in your .NET code that you want to call from MaxScript. This is useful for extending MaxScript by adding your own functionality that interacts with its objects and variables.

This can be achieved relatively easy with Max.NET: we can call any static (or member) function by using MaxScript's .NET exposure. Let us first define our pluggable Max.NET class with a callback function in it:

using Autodesk.Max;

namespace MyProject
{
public class Plugin : IPlugin
{

public void MyCallback()
{
      // Do something...
}

// IPlugin Implementation...

}
}

We can then call MyCallback() function from 3dsmax listener or script as follows:

( dotNetObject "MyProject.Plugin" ).MyCallback()

 
Comments
 

Thanks, finally i can use C# into maxscript  \('_')/ . For noobs like me you can test this :

using System;
using Autodesk.Max;
using Autodesk.Max.Plugins;

namespace MyProject
{
    public class MyPlugin : IPlugin
    {
        void IPlugin.Cleanup() {}
        void IPlugin.Initialize(IGlobal global, System.ComponentModel.ISynchronizeInvoke sync) { }
        public String MyTestFunction() { return "return"; }
    }
}

Save the compiled test.dll into MaxRoot\plugins and run into listener

(dotNetObject "MyProject.MyPlugin").MyTestFunction()