» Back to Documentation

Here is a helpful little snipper to execute MaxScript from inside a Max.NET plugin:

internal static IValue MaxScriptExecute( string str, IGlobal global )
        {
            bool res = false;
            return global.ExecuteScript( global.StringStream.Create( str ), /*ref */res );
        }

An example of usage:

IINode myNode = MaxScriptExecute( "$myNode", global ).ToNode;

For more information on getting access to IGlobal object please refer here.

Another helpful snippet to print to the 3ds Max listener window:

public static void Log( string message, bool newLine )
        {
            global.TheListener.EditStream.Printf( message + ( newLine ? Environment.NewLine : string.Empty ), null );
        }

 

 
Comments
 

how can declare the 'global' parameter in here:

string myNode = MaxScriptExecute("$myNode", global).ToNode; 

I have answered this question here.

Thank you.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hello,

I'm a noob when it comes to C#, and I'm trying to get any text to print to the Listener in Max via a button click in a C# form.

I'm using the function you provided above, but how would I go about calling it properly? 

I've tried this, to no avail.

 

private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Hello World");
            Log("weee",  false, global);
        }

 

Thank you

It seems you're passing false for the newLine parameter. You need to end your message with a "\n" for it to be displayed in the listener. Hope this helps.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Awesome, that worked :D

I have another question...

I saw you had a post, on what looked like adding a menu item for a plugin to be executedwith.

I was wondering how to go about reloading the .dll/Plugin through maxscript, so I could close/re-open the C# Menu I made, via another fucntion/button in max?

Is that somewhat of a process, or no?

Thanks!

Not sure if this is what you mean but if you overwrite your .dll file while 3dsmax is loaded, max.net will attempt to reload the plugin for you (calling the Cleanup and Initialize methods). You do need to turn on plugin unloading in max.net settings (utilities menu), there is no other way to reload plugin without restarting 3dsmax.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Ah....ok.  Well, turning that option on, stopped me from getting the copy error because the .dll is in memory. But the menu does not pop up again after it's done copying. 

At work they are using a C++ or C# menu in Max, and theres a menu option at the top to open the tool if closed.  Is that what you are doing in that example?  So that seems to be the only way to reopen it then , correct?

Thanks again,

Matt