初次接触Navisworks Api .NET 的二次开发.主要是研究了一下。关于NavisWorks 结构树的加载.
void LoadModel() { //清空当前的结构树信息 treeView1.Nodes.Clear(); //当前加载的模型 Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; //循环现有模型 foreach (var documentModel in doc.Models) { var modelItemList = documentModel.RootItem.Descendants; Model model = documentModel; var modelItems = modelItemList.Where(o => o.Parent == model.RootItem); if (modelItems.Any()) { TreeNode cNode; foreach (var quItem in modelItems) { cNode = new TreeNode(quItem.DisplayName); cNode.Tag = quItem; // cNode.Text = quItem.DisplayName;//判断名称 treeView1.Nodes.Add(cNode); if (quItem.Children.Any()) { LoadChild(quItem.Children, quItem, cNode); } } } } } /// <summary> /// 递归判断结构树信息 /// </summary> /// <param name="modelItemEnumerableCollection">数据源信息</param> /// <param name="parentItem">父级节点信息</param> /// <param name="pNode">子节点信息</param> private void LoadChild(IEnumerable<ModelItem> modelItemEnumerableCollection, ModelItem parentItem, TreeNode pNode) { var query = modelItemEnumerableCollection.Where(o => o.Parent == parentItem); if (query.Count()>0) { foreach (var quItem in query) { TreeNode chNode = new TreeNode(quItem.DisplayName); chNode.Tag = quItem; pNode.Nodes.Add(chNode); if (quItem.Children.Any()) { LoadChild(quItem.Children, quItem, chNode); } } } }
TreeView Node 选中事件
void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode node = e.Node; if (node != null) { ModelItem oCurrentNode = (ModelItem)node.Tag; propertyGrid1.SelectedObject = oCurrentNode; if (oCurrentNode != null) { //设置选择集合 ModelItemCollection oMC = new ModelItemCollection(); oMC.Add(oCurrentNode); Document oDoc = view.ViewControl.DocumentControl.Document; //设置选中 oDoc.CurrentSelection.CopyFrom(oMC); } } }
主要是刚接触这个.不懂 只是自己在这写的。如果那位网友有更好的解决方案。请告诉我.谢谢哈