private void GetTreeData(MainWinVM mainWinVM) { PLMProductService service = (PLMProductService)CatiaService.catia.ActiveEditor.GetService("PLMProductService"); VPMRootOccurrence vpmRootOcc = service.RootOccurrence; VPMReference vpmRefOnRoot = vpmRootOcc.ReferenceRootOccurrenceOf; // get all children of the root VPMInstances vpmInstsL1 = vpmRefOnRoot.Instances; DefinitionNode rootNode = new DefinitionNode(); rootNode.Name = vpmRefOnRoot.GetAttributeValue("V_Name"); mainWinVM.DefinitionNodes = new ObservableCollection <DefinitionNode>(); mainWinVM.DefinitionNodes.Add(rootNode); Recursion(vpmInstsL1, rootNode); }
private void Recursion(PLMEntities vpmInsts, DefinitionNode node) { ObservableCollection <DefinitionNode> definitionNodes = new ObservableCollection <DefinitionNode>(); for (int i = 1; i < vpmInsts.Count + 1; i++) { DefinitionNode definitionNode = new DefinitionNode(); VPMInstance vpmInstL1 = vpmInsts.Item(i) as VPMInstance; VPMReference vpmRefInstL1 = vpmInstL1.ReferenceInstanceOf; definitionNode.Name = vpmRefInstL1.GetAttributeValue("V_Name"); definitionNodes.Add(definitionNode); VPMInstances vpmInstsL2 = vpmRefInstL1.Instances; if (vpmInstsL2.Count > 0) { Recursion(vpmInstsL2, definitionNode); } else { VPMRepInstances vpmRefInstsL3 = vpmRefInstL1.RepInstances; ObservableCollection <DefinitionNode> nodes = new ObservableCollection <DefinitionNode>(); for (int k = i; k < vpmRefInstsL3.Count + 1; k++) { VPMRepInstance vpmRepInstL3 = vpmRefInstsL3.Item(k) as VPMRepInstance; VPMRepReference vpmRepRefL3 = vpmRepInstL3.ReferenceInstanceOf; DefinitionNode oneNode = new DefinitionNode(); oneNode.Name = vpmRepRefL3.GetAttributeValue("V_Name"); nodes.Add(oneNode); } definitionNode.Children = nodes; } } node.Children = definitionNodes; }