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);
}
初学,分享给大家。