private List <LinkedFamilyInfo> FindFamilyMappingNode(TreeViewFamilyModel parentNode)
        {
            var linkedFamilies = new List <LinkedFamilyInfo>();

            try
            {
                foreach (var node in parentNode.ChildrenNodes)
                {
                    if (node.NodeType == TreeViewNodeType.FamilyType)
                    {
                        if (node.IsChecked == true)
                        {
                            var linkedInfo = node.Tag as LinkedFamilyInfo;
                            if (null != linkedInfo)
                            {
                                linkedFamilies.Add(linkedInfo);
                            }
                        }
                    }
                    else
                    {
                        var infoList = FindFamilyMappingNode(node);
                        if (infoList.Count > 0)
                        {
                            linkedFamilies.AddRange(infoList);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find mapping node.\n" + ex.Message, "Find Mapping Node", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(linkedFamilies);
        }
Esempio n. 2
0
        public static List <TreeViewFamilyModel> SetTreeView(LinkedInstanceProperties lip)
        {
            var treeView = new List <TreeViewFamilyModel>();

            try
            {
                var categories = from linkedFamily in lip.LinkedFamilies.Values select linkedFamily.CategoryName;
                if (categories.Count() > 0)
                {
                    var categoryNames = categories.Distinct().ToList(); categoryNames.Sort();
                    foreach (var categoryName in categoryNames)
                    {
                        var categoryNode = new TreeViewFamilyModel(categoryName);
                        categoryNode.NodeType = TreeViewNodeType.Category;
                        treeView.Add(categoryNode);

                        var families = from linkedFamily in lip.LinkedFamilies.Values
                                       where linkedFamily.CategoryName == categoryName
                                       select linkedFamily.SourceFamilyName;
                        if (families.Count() > 0)
                        {
                            var familyNames = families.Distinct().ToList(); familyNames.Sort();
                            foreach (var familyName in familyNames)
                            {
                                var linkedFamilies = from linkedFamily in lip.LinkedFamilies.Values
                                                     where linkedFamily.CategoryName == categoryName && linkedFamily.SourceFamilyName == familyName
                                                     select linkedFamily;

                                if (linkedFamilies.Count() > 0)
                                {
                                    var familyInfo = linkedFamilies.First();

                                    var familyNode = new TreeViewFamilyModel(familyInfo.SourceFamilyName + " : " + familyInfo.TargetFamilyName);
                                    familyNode.NodeType = TreeViewNodeType.Family;
                                    categoryNode.ChildrenNodes.Add(familyNode);

                                    var familyTypes = linkedFamilies.OrderBy(o => o.SourceTypeName).ToList();
                                    foreach (var linkedInfo in familyTypes)
                                    {
                                        var familyTypeNode = new TreeViewFamilyModel(linkedInfo.SourceTypeName + " : " + linkedInfo.TargetTypeName);
                                        familyTypeNode.NodeType = TreeViewNodeType.FamilyType;
                                        familyTypeNode.Tag      = linkedInfo;
                                        familyNode.ChildrenNodes.Add(familyTypeNode);
                                    }
                                }
                            }
                        }
                        categoryNode.Initialize();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to set the tree view.\n" + ex.Message, "Set Tree View", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(treeView);
        }
        private void comboBoxLink_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (null != comboBoxLink.SelectedItem)
                {
                    selectedLink = (LinkedInstanceProperties)comboBoxLink.SelectedItem;
                    treeViewMapping.ItemsSource = null;
                    treeViewMapping.ItemsSource = TreeViewElementModel.SetTreeView(selectedLink);

                    treeViewFamilyMapping.ItemsSource = null;
                    treeViewFamilyMapping.ItemsSource = TreeViewFamilyModel.SetTreeView(selectedLink);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to select a Revit Link.\n" + ex.Message, "Select a Revit Link", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }