3ds Max .NET SDK由以下.NET程序集組成。
- Autodesk.Max.dll - Contains wrappers that expose most of the API elements from the 3ds Max C++ SDK to .NET constructs. Currently it is not recommended to derive from the Autodesk.Max.Plugins classes.
- AssemblyLoader.dll - Contains the Loader class.
- CSharpUtilities.dll - Various utility classes for .NET programming.
- ExplorerFramework.dll - Abstract explorer framework classes upon which the Scene Explorer is built. It can be used for creating a new node traversal for arbitrary scene explorers.
- ManagedServices.dll - Exposes some convenient 3ds Max SDK functionality to .NET.
- MaxCustomControls.dll - Various .NET utilities and UI components.
- SceneExplorer.dll - Specification of the ExplorerFramework components for the SceneExplorer with bindings to 3ds Max data.
- UiViewModels.dll - Contains classes for defining user actions and customizing the user interface.
以上摘自說明文檔。
3ds Max從bin / assemblies文件夾中加載插件。
public static class AssemblyEntry
{
/// <summary>
/// 啓動時候執行.
/// </summary>
/// <author>YangSen</author>
public static void AssemblyMain()
{
try
{
{
// 在這裏可以做一些UI,便於後續使用,我在Help的下拉中加了一個菜單項
RibbonMenuItem mi = new RibbonMenuItem();
mi.Id = "ID_MODIFY_NAME";
mi.IsVisible = true;
mi.Text = "Rename By IFD Code";
mi.Description = "Rename By IFD Code";
mi.ShowText = true;
// RenameCommand爲綁定的命令,該命令繼承了System.Windows.Input.ICommand接口
mi.CommandHandler = new RenameCommand();
ComponentManager.HelpButton.Items.Add(mi);
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 關閉時候執行.
/// </summary>
/// <author>YangSen</author>
public static void AssemblyShutdown()
{
// do something...
}
}
RenameCommand命令
public class RenameCommand : System.Windows.Input.ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
// do something...
}
}
以上是初次研究的成果,對於腳本插件還沒有深入研究。
在public void Execute(object parameter)中,我們可以做我們想做的事情,比如:
var g = Autodesk.Max.GlobalInterface.Instance;
var core = g.COREInterface14;
IINode proj = core.RootNode;
if (proj.NumChildren > 1)
{
// 添加組
core.ClearNodeSelection(true); // 清除選擇
for (int i = 0; i < proj.NumChildren; i++)
{
var nd = proj.GetChildNode(i); // 獲取子節點
core.SelectNode(nd, false); // 添加選擇,false表示不清除之前的選擇
}
// 解釋一下GroupNodes這個方法
// 第一個參數爲空,默認爲當前選擇的節點
// 第二個參數爲空,默認會彈出一個編輯對話框
// 第三個參數爲false,標識不選中分組
IINode groupNode = core.GroupNodes(null, IntPtr.Zero, false);
}
初學,分享給大家。