Posted by Christopher Diggins, 8 June 2012 6:06 pm
I've adventured deep into the darkest corners of the 3ds Max SDK to bring you a set of largely unknown but useful tips and tricks.
Use the 3ds Max SDK from MAXScript by loading the Autodesk.Max.dll. Add the following MAXScript to your start-up scripts and you can use the MaxGlobal variable to access the 3ds Max SDK.
fn loadAutodeskMax = ( local Assembly = dotNetClass "System.Reflection.Assembly" local maxroot = pathConfig.GetDir #maxroot Assembly.LoadFile (maxroot + "\Autodesk.Max.dll") local GlobalInterface = dotNetClass "Autodesk.Max.GlobalInterface" global MaxGlobal = GlobalInterface.Instance ) loadAutodeskMax ()
#define WM_TRIGGER_CALLBACK WM_USER+4764
void PostCallback( void (*funcPtr)(UINT_PTR), UINT_PTR param )
{
PostMessage( GetAppHWnd(), WM_TRIGGER_CALLBACK,
(UINT_PTR)funcPtr, (UINT_PTR)param );
}
the_listener->edit_stream->wputs("Hello")
the_listener->edit_stream->flush()
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public static void RunPythonFile(string filename) {
try {
var options = new Dictionary<string, object>();
options["Debug"] = true;
ScriptEngine se = Python.CreateEngine(options);
ScriptSource ss = se.CreateScriptSourceFromFile(filename);
CompiledCode cc = ss.Compile();
cc.Execute();
}
catch (Exception e){
MessageBox.Show("Error occurred: " + e.Message);
}
}
using ManagedServices;
public class My3dsMaxAssembly
{
public const int StartUpNotification = 0x50;
public static void AssemblyMain()
{
// This causes an event to be raised once the 3ds Max application has been started
var m = new MaxNotificationListener(StartUpNotification);
m.NotificationRaised += new EventHandler<MaxNotificationEventArgs>(AfterStartup);
}
public static void AfterStartup(object sender, MaxNotificationEventArgs e) {
if (e.NotificationCode == StartUpNotification) {
// Do whatever
}
}
}
Special thanks to Michaelson Britt, Stephen Taylor, and David Cunningham for several of theses cool tips. Please share in the comments your favorite undocumented or frequently overlooked tips and tricks for using the 3ds Max SDK!
Please only report comments that are spam or abusive.
13 Comments
JokerMartini
Posted 9 June 2012 7:08 pm
On a side note I've recently come across the issue where my maxscript listener no longer records anything I do. Is there a fix to that?
Great blog, keep up the work. Thanks Christopher.
- John
- www.JokerMartini.com
lo_
Posted 10 June 2012 6:49 am
(uppercase MAX)
Christopher Diggins
Posted 11 June 2012 6:47 pm
@lo_ Thanks for the support and the correction. I made the change.
spacefrog
Posted 11 June 2012 7:30 pm
not really tutorials or such but a great resource of collected Max SDK knowledge. Just in case you did' know this forum ...
http://dl3d.free.fr/phpBB2/viewforum.php?f=3
And of course not to miss Dacid Lanier's free Book/PDF about Max SDK programming. Parts of it might be obsolete by now, but nvertheless a great read ..
http://dl3d.free.fr/resources/3DSMAX_SDK_DavidLanier.pdf
Jake Jeziorski
Posted 12 June 2012 8:36 am
Thank you very much.
JokerMartini
Posted 12 June 2012 8:58 pm
I want to write it in c++ and then make it a plugin for 3ds max.
I'll check out the SDK section which was mentioned above.
Where is the best community to post snippets and get feedback on developing these types of tools for max?
Klunk
Posted 18 June 2012 8:52 pm
this however
#include "maxscrpt/maxscrpt.h"
#include "maxscrpt/Listener.h"
the_listener->edit_stream->wputs("Hello" ) ;
the_listener->edit_stream->flush();
should compile
Christopher Diggins
Posted 19 June 2012 5:31 pm
Klunk
Posted 20 June 2012 12:35 pm
Shawn Olson
Posted 3 October 2012 3:17 am
All info seems to assume knowledge of C++/C# ... and many of us have no real background in that. At the same time, a good transitional guide would help us get going faster and probably make it easier for us to absorb C++/C#.
Klunk
Posted 12 January 2013 9:45 pm
Klunk
Posted 13 January 2013 7:23 am
powernemo
Posted 24 April 2013 9:41 pm
I have a question about ExecuteMAXScriptScript() if you don`t mind.
The third parameter is an IFPValue but is not clear how to obtain this from C#, I would like to get a return value from this :
var tp = IGlobal.ExecuteMAXScriptScript("Teapot()", true, «???»);
but all the usages I`ve seen in the SDK and your MaxSharp use "null" instead.
Thank you
Add Your Comment
You must be logged in to post a comment. Login or Register here