码迷,mamicode.com
首页 > 其他好文 > 详细

25 things you probably didn't know about the 3ds Max SDK

时间:2016-08-15 14:11:27      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

 

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.

  1. 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 ()
    View Code
  2. Execute arbitrary MAXScript code using the ExecuteMAXScriptScript() global function (see the maxscript\maxscript.h header).
  3. 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.
    技术分享
    1 #define WM_TRIGGER_CALLBACK WM_USER+4764
    2 void PostCallback( void (*funcPtr)(UINT_PTR), UINT_PTR param )
    3 {
    4   PostMessage( GetAppHWnd(), WM_TRIGGER_CALLBACK, 
    5     (UINT_PTR)funcPtr, (UINT_PTR)param );
    6 }
    View Code
  4. Work with different types of meshes ( Mesh, MNMesh and PatchMesh) using the ObjectWrapper class. This can simplify writing plug-in that have to deal with arbitrary mesh types such as modifiers.
  5. Collect notifications about all nodes in the scene in an efficient way using the ISceneEventManager class. It‘s ideal to use for UI refresh, when you need to monitor the scene for events to trigger a refresh.
  6. Output text to the 3ds Max MAXScript listener window (see the maxscript\maxscript.h header) as follows:
    技术分享
    1   the_listener->edit_stream->wputs("Hello") 
    2   the_listener->edit_stream->flush()
    View Code
  7. Execute a Python script from a .NET assembly with a few lines of code after downloading and installing IronPython
    技术分享
     1 using IronPython.Hosting;
     2 using Microsoft.Scripting.Hosting;
     3 public static void RunPythonFile(string filename) {
     4   try  {
     5      var options = new Dictionary<string, object>();
     6      options["Debug"] = true;
     7      ScriptEngine se = Python.CreateEngine(options);
     8      ScriptSource ss = se.CreateScriptSourceFromFile(filename);
     9      CompiledCode cc = ss.Compile();
    10      cc.Execute();
    11    }
    12   catch (Exception e){
    13     MessageBox.Show("Error occurred: " + e.Message);
    14   }
    15 }
    View Code
  8. Extend 3ds Max with new drag and drop functionality by deriving from the DragAndDropHandler class.
  9. Download a file from an arbitrary URL to disk using: IDragAndDropMgr::DownloadUrlToDisk().
  10. Compress data using the zlip compression library. Check out the zlibdll.h header file in the 3ds Max SDK.
  11. Log messages to the 3ds Max log file and even print out messages to Visual Studio console using LogSys class.
  12. Evaluate mathematical expressions stored as strings using the Expr class.
  13. Generate repeatable sequences of random numbers using the Random class.
  14. Store objects in one of the following container template types:
  15. Read and write Unicode files easily and correctly using the FileReaderWriter class.
  16. Compute the time it takes to complete a task using the Timer class.
  17. Automatically delete objects when you are done with them using the AutoPtr template.
  18. Output unobtrusive status messages to the user using the Interface::PushPrompt() function.
  19. Retrieve the user define UI colors using IColorManager.
  20. Launch a web browser using IBrowserMgr.
  21. Retrieve .MAX file properties using Interface11::OpenMaxStorageFile().
  22. Format a time value as a string using Interface10::FormatRenderTime()
  23. Open the windows explorer using Interface8::RevealInExplorer().
  24. Perform a quick render to a bitmap using Interface8::QuickRender()
  25. Execute code when 3ds Max is fully initialized in C#:
    技术分享
     1 using ManagedServices;
     2 public class My3dsMaxAssembly
     3 {
     4   public const int StartUpNotification = 0x50;
     5   public static void AssemblyMain()
     6   {
     7     // This causes an event to be raised once the 3ds Max application has been started 
     8     var m = new MaxNotificationListener(StartUpNotification);
     9     m.NotificationRaised += new EventHandler<MaxNotificationEventArgs>(AfterStartup); 
    10   } 
    11   public static void AfterStartup(object sender, MaxNotificationEventArgs e) { 
    12     if (e.NotificationCode == StartUpNotification) { 
    13       // Do whatever 
    14     } 
    15   } 
    16 } 
    View Code

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!

 

25 things you probably didn't know about the 3ds Max SDK

标签:

原文地址:http://www.cnblogs.com/sunlery/p/5772660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!