Notifications
Clear all

[Closed] ExecuteMaxscriptCommand compiler error

Hi,I’m trying to use ExecuteMaxscriptCommand to run maxscript code,I got a Runtime error,how to fix it?Thanks in advance.

(
    local compilerParams = dotNetObject "System.CodeDom.Compiler.CompilerParameters" #(
        getDir #maxRoot + "Autodesk.Max.dll",
        getDir #maxRoot + "\bin\assemblies\Autodesk.Max.Wrappers.dll"
	)
    compilerParams.GenerateInMemory = on

    local compilerResults = (dotNetObject "Microsoft.CSharp.CSharpCodeProvider").CompileAssemblyFromSource compilerParams #(
        "using Autodesk.Max;
        using Wrappers = Autodesk.Max.Wrappers;

        public class Gomax
		{
			private static readonly IGlobal Global = Autodesk.Max.GlobalInterface.Instance;

            public static void Run_script() 
			{
                ExecuteMaxscriptCommand(\"print 123\");
            }
        }"
    )
    for err = 0 to compilerResults.errors.count - 1 do print (compilerResults.errors.item[err].ToString())
    Test = compilerResults.CompiledAssembly.CreateInstance "Gomax"
)
Test.Run_script()
1 Reply

Then you need ManagedServices.dll from the max root dir

(dotNetClass "ManagedServices.MAXScriptSDK").ExecuteMAXScriptCommand