【转】25 things you probably didn't know about the 3ds Max SDK
http://area.autodesk.com/blogs/chris/25-things-you-probably-didn039t-know-about-the-3ds-max-sdk
25 things you probably didn't know about the 3ds Max SDK
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 ()
- Execute arbitrary MAXScript code using the ExecuteMAXScriptScript() global function (see the maxscriptmaxscript.h header).
- Execute code safely in the main thread in 3ds Max by either creating a Windows timer object using the main 3ds Max window as the window handle, or by using the following function to trigger code as soon as 3ds Max is idle next.
#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 ); } - Work with different types of meshes ( Mesh, MNMesh and PatchMesh) using theObjectWrapper class. This can simplify writing plug-in that have to deal with arbitrary mesh types such as modifiers.
- Collect notifications about all nodes in the scene in an efficient way using theISceneEventManager class. It's ideal to use for UI refresh, when you need to monitor the scene for events to trigger a refresh.
- Output text to the 3ds Max MAXScript listener window (see the maxscriptmaxscript.h header) as follows:
the_listener->edit_stream->wputs("Hello") the_listener->edit_stream->flush()
- Execute a Python script from a .NET assembly with a few lines of code after downloading and installing IronPython
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); } }
- Extend 3ds Max with new drag and drop functionality by deriving from theDragAndDropHandler class.
- Download a file from an arbitrary URL to disk using:IDragAndDropMgr::DownloadUrlToDisk().
- Compress data using the zlip compression library. Check out the zlibdll.h header file in the 3ds Max SDK.
- Log messages to the 3ds Max log file and even print out messages to Visual Studio console using LogSys class.
- Evaluate mathematical expressions stored as strings using the Expr class.
- Generate repeatable sequences of random numbers using the Random class.
- Store objects in one of the following container template types:
- Read and write Unicode files easily and correctly using the FileReaderWriter class.
- Compute the time it takes to complete a task using the Timer class.
- Automatically delete objects when you are done with them using the AutoPtrtemplate.
- Output unobtrusive status messages to the user using the Interface::PushPrompt()function.
- Retrieve the user define UI colors using IColorManager.
- Launch a web browser using IBrowserMgr.
- Retrieve .MAX file properties using Interface11::OpenMaxStorageFile().
- Format a time value as a string using Interface10::FormatRenderTime()
- Open the windows explorer using Interface8::RevealInExplorer().
- Perform a quick render to a bitmap using Interface8::QuickRender()
- Execute code when 3ds Max is fully initialized in C#:
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!