overview
NW操作模型主要通过Model
和ModelItem
两个类。
遍历树
Document document = Autodesk.Navisworks.Api.Application.ActiveDocument;
// 获取第一个模型文件
Model model = document.Models[0];
// 获取目录树中的所有节点
ModelItemEnumerableCollection modelItems = model.RootItem.DescendantsAndSelf;
// 遍历每个对象
foreach (ModelItem modelItem in modelItems)
{
MessageBox.Show(modelItem.DisplayName);
}
上述代码主要是通过目录树的方式,去操作模型对象。
获取选择对象
Document document = Autodesk.Navisworks.Api.Application.ActiveDocument;
// 获取当前选择的对象集合
DocumentCurrentSelection dcs = document.CurrentSelection;
ModelItemCollection modelItems = dcs.SelectedItems;
// 遍历每个对象
foreach (ModelItem modelItem in modelItems)
{
MessageBox.Show(modelItem.DisplayName);
}
上述代码主要是通过3D模型选取的方式,获取对象。