现在的位置: 首页 > 综合 > 正文

【转】25 things you probably didn’t know about the 3ds Max SDK

2013年06月01日 ⁄ 综合 ⁄ 共 3964字 ⁄ 字号 评论关闭
文章目录

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.

  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 ()
    
  2. Execute arbitrary MAXScript code using the ExecuteMAXScriptScript() global function (see the maxscriptmaxscript.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.
    #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 ); }
  4. 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.
  5. 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.
  6. 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()
    
  7. 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);
      }
    }
    
  8. Extend 3ds Max with new drag and drop functionality by deriving from theDragAndDropHandler 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 AutoPtrtemplate.
  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#:
    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!

抱歉!评论已关闭.