Пример #1
0
        private void RefreshElementTypesList(ListBox listBox, ComboBox categoriesBox, ComboBox familiesBox)
        {
            var doc = Revit.ActiveUIDocument.Document;

            listBox.SelectedIndexChanged -= ElementTypesBox_SelectedIndexChanged;
            listBox.Items.Clear();

            {
                var categories = (
                    categoriesBox.SelectedItem is Types.Category category ?
                    Enumerable.Repeat(category, 1) :
                    categoriesBox.Items.OfType <Types.Category>()
                    ).
                                 Select(x => x.Id).
                                 ToArray();

                if (categories.Length > 0)
                {
                    var elementTypes = default(IEnumerable <DB.ElementId>);
                    using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document))
                    {
                        elementTypes = collector.WhereElementIsElementType().
                                       WherePasses(new DB.ElementMulticategoryFilter(categories)).
                                       ToElementIds();
                    }

                    var familyName = familiesBox.SelectedItem as string;

                    listBox.DisplayMember = "DisplayName";
                    foreach (var elementType in elementTypes)
                    {
                        if
                        (
                            !string.IsNullOrEmpty(familyName) &&
                            doc.GetElement(elementType) is DB.ElementType type &&
                            type.GetFamilyName() != familyName
                        )
                        {
                            continue;
                        }

                        listBox.Items.Add(Types.ElementType.FromElementId(doc, elementType));
                    }
                }
            }

            listBox.SelectedIndex         = listBox.Items.OfType <Types.ElementType>().IndexOf(Current, 0).FirstOr(-1);
            listBox.SelectedIndexChanged += ElementTypesBox_SelectedIndexChanged;
        }
Пример #2
0
        private void RefreshFamiliesBox(ComboBox familiesBox, ComboBox categoriesBox)
        {
            familiesBox.SelectedIndex = -1;
            familiesBox.Items.Clear();

            using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document))
            {
                var categories = GetCategoryIds(categoriesBox);

                foreach (var familyName in collector.WhereElementIsElementType().OfClass(typeof(R)).
                         WherePasses(new DB.ElementMulticategoryFilter(categories)).Cast <R>().
                         GroupBy(x => x.GetFamilyName()).Select(x => x.Key))
                {
                    familiesBox.Items.Add(familyName);
                }
            }
        }
Пример #3
0
        private void RefreshElementTypesList(ListBox listBox, ComboBox categoriesBox, ComboBox familiesBox)
        {
            var doc = Revit.ActiveUIDocument.Document;

            listBox.SelectedIndexChanged -= ElementTypesBox_SelectedIndexChanged;
            listBox.Items.Clear();

            {
                var categories = GetCategoryIds(categoriesBox);
                if (categories.Length > 0)
                {
                    var elementTypes = default(IEnumerable <R>);
                    using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document))
                    {
                        elementTypes = collector.WhereElementIsElementType().OfClass(typeof(R)).
                                       WherePasses(new DB.ElementMulticategoryFilter(categories)).Cast <R>();

                        var familyName = familiesBox.SelectedItem as string;

                        listBox.DisplayMember = "DisplayName";
                        foreach (var elementType in elementTypes)
                        {
                            if
                            (
                                !string.IsNullOrEmpty(familyName) &&
                                elementType.GetFamilyName() != familyName
                            )
                            {
                                continue;
                            }

                            listBox.Items.Add(Types.ElementType.FromElement(elementType));
                        }
                    }
                }
            }

            listBox.SelectedIndex         = listBox.Items.OfType <T>().IndexOf(Current, 0).FirstOr(-1);
            listBox.SelectedIndexChanged += ElementTypesBox_SelectedIndexChanged;
        }
Пример #4
0
        private void RefreshFamiliesBox(ComboBox familiesBox, ComboBox categoriesBox)
        {
            familiesBox.SelectedIndex = -1;
            familiesBox.Items.Clear();

            using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document))
            {
                var categories = (
                    categoriesBox.SelectedItem is Types.Category category ?
                    Enumerable.Repeat(category, 1) :
                    categoriesBox.Items.OfType <Types.Category>()
                    ).
                                 Select(x => x.Id).
                                 ToArray();

                foreach (var familyName in collector.WhereElementIsElementType().
                         WherePasses(new DB.ElementMulticategoryFilter(categories)).
                         ToElements().Cast <DB.ElementType>().GroupBy(x => x.GetFamilyName()).Select(x => x.Key))
                {
                    familiesBox.Items.Add(familyName);
                }
            }
        }
Пример #5
0
        protected override void RefreshList(IEnumerable <IGH_Goo> goos)
        {
            var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList();

            ListItems.Clear();

            if (Revit.ActiveDBDocument is DB.Document doc)
            {
                int selectedItemsCount = 0;
                using (var collector = new DB.FilteredElementCollector(doc))
                    using (var elementTypeCollector = collector.WhereElementIsElementType())
                    {
                        foreach (var goo in goos)
                        {
                            var e = new Types.Element();
                            if (e.CastFrom(goo))
                            {
                                switch (e.Value)
                                {
                                case DB.Family family:
                                    foreach (var elementType in elementTypeCollector.Cast <DB.ElementType>())
                                    {
                                        if (elementType.GetFamilyName() != family.Name)
                                        {
                                            continue;
                                        }

                                        var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), elementType.UniqueId);
                                        var item        = new GH_ValueListItem($"{elementType.GetFamilyName()} : {elementType.Name}", $"\"{referenceId}\"");
                                        item.Selected = selectedItems.Contains(item.Expression);
                                        ListItems.Add(item);

                                        selectedItemsCount += item.Selected ? 1 : 0;
                                    }
                                    break;

                                case DB.ElementType elementType:
                                {
                                    var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), elementType.UniqueId);
                                    var item        = new GH_ValueListItem(elementType.GetFamilyName() + " : " + elementType.Name, $"\"{referenceId}\"");
                                    item.Selected = selectedItems.Contains(item.Expression);
                                    ListItems.Add(item);

                                    selectedItemsCount += item.Selected ? 1 : 0;
                                }
                                break;

                                case DB.Element element:
                                {
                                    var type        = doc.GetElement(element.GetTypeId()) as DB.ElementType;
                                    var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), type.UniqueId);
                                    var item        = new GH_ValueListItem(type.GetFamilyName() + " : " + type.Name, $"\"{referenceId}\"");
                                    item.Selected = selectedItems.Contains(item.Expression);
                                    ListItems.Add(item);

                                    selectedItemsCount += item.Selected ? 1 : 0;
                                }
                                break;
                                }
                            }
                            else
                            {
                                var c = new Types.Category();
                                if (c.CastFrom(goo))
                                {
                                    foreach (var elementType in elementTypeCollector.WhereCategoryIdEqualsTo(c.Id).Cast <DB.ElementType>())
                                    {
                                        var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), elementType.UniqueId);
                                        var item        = new GH_ValueListItem(elementType.GetFamilyName() + " : " + elementType.Name, $"\"{referenceId}\"");
                                        item.Selected = selectedItems.Contains(item.Expression);
                                        ListItems.Add(item);

                                        selectedItemsCount += item.Selected ? 1 : 0;
                                    }
                                }
                                else
                                {
                                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to convert some input data.");
                                }
                            }
                        }
                    }

                // If no selection and we are not in CheckList mode try to select default model types
                if (ListItems.Count > 0 && selectedItemsCount == 0 && ListMode != GH_ValueListMode.CheckList)
                {
                    var defaultElementTypeIds = new HashSet <string>();
                    foreach (var typeGroup in Enum.GetValues(typeof(DB.ElementTypeGroup)).Cast <DB.ElementTypeGroup>())
                    {
                        var elementTypeId = doc.GetDefaultElementTypeId(typeGroup);
                        if (elementTypeId != DB.ElementId.InvalidElementId)
                        {
                            var type        = doc.GetElement(elementTypeId);
                            var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), type.UniqueId);
                            defaultElementTypeIds.Add(elementTypeId.IntegerValue.ToString());
                        }
                    }

                    foreach (var item in ListItems)
                    {
                        item.Selected = defaultElementTypeIds.Contains(item.Expression);
                    }
                }
            }
        }
Пример #6
0
        protected override void RefreshList(string familyName)
        {
            var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList();

            ListItems.Clear();

            if (familyName.Length == 0 || familyName[0] == '\'')
            {
                return;
            }

            if (Revit.ActiveDBDocument is DB.Document doc)
            {
                int selectedItemsCount = 0;
                using (var collector = new DB.FilteredElementCollector(doc))
                {
                    var elementCollector = collector.WhereElementIsElementType();

                    if (Components.ElementCollectorComponent.TryGetFilterStringParam(DB.BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM, ref familyName, out var familyNameFilter))
                    {
                        elementCollector = elementCollector.WherePasses(familyNameFilter);
                    }

                    var elementTypes = elementCollector.Cast <DB.ElementType>();

                    foreach (var elementType in elementTypes)
                    {
                        if (familyName is object)
                        {
                            if (!elementType.GetFamilyName().IsSymbolNameLike(familyName))
                            {
                                continue;
                            }
                        }

                        if (SourceCount == 0)
                        {
                            // If is a no pattern match update NickName case
                            if (string.Equals(elementType.GetFamilyName(), familyName, StringComparison.OrdinalIgnoreCase))
                            {
                                familyName = elementType.GetFamilyName();
                            }
                        }

                        var referenceId = FullUniqueId.Format(doc.GetFingerprintGUID(), elementType.UniqueId);
                        var item        = new GH_ValueListItem($"{elementType.GetFamilyName()}  : {elementType.Name}", $"\"{referenceId}\"");
                        item.Selected = selectedItems.Contains(item.Expression);
                        ListItems.Add(item);

                        selectedItemsCount += item.Selected ? 1 : 0;
                    }
                }

                // If no selection and we are not in CheckList mode try to select default model types
                if (ListItems.Count == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No ElementType found using pattern \"{0}\"", familyName));
                }
                else if (selectedItemsCount == 0 && ListMode != GH_ValueListMode.CheckList)
                {
                    var defaultElementTypeIds = new HashSet <string>();
                    foreach (var typeGroup in Enum.GetValues(typeof(DB.ElementTypeGroup)).Cast <DB.ElementTypeGroup>())
                    {
                        var elementTypeId = Revit.ActiveDBDocument.GetDefaultElementTypeId(typeGroup);
                        if (elementTypeId != DB.ElementId.InvalidElementId)
                        {
                            defaultElementTypeIds.Add(elementTypeId.IntegerValue.ToString());
                        }
                    }

                    foreach (var item in ListItems)
                    {
                        item.Selected = defaultElementTypeIds.Contains(item.Expression);
                    }
                }
            }
        }
Пример #7
0
        protected override void RefreshList(string FamilyName)
        {
            var selectedItems = ListItems.Where(x => x.Selected).Select(x => x.Expression).ToList();

            ListItems.Clear();

            if (FamilyName.Length == 0 || FamilyName[0] == '\'')
            {
                return;
            }

            if (Revit.ActiveDBDocument is object)
            {
                int selectedItemsCount = 0;
                using (var collector = new DB.FilteredElementCollector(Revit.ActiveDBDocument))
                {
                    foreach (var elementType in collector.WhereElementIsElementType().Cast <DB.ElementType>())
                    {
                        if (!elementType.FamilyName.IsSymbolNameLike(FamilyName))
                        {
                            continue;
                        }

                        if (SourceCount == 0)
                        {
                            // If is a no pattern match update NickName case
                            if (string.Equals(elementType.FamilyName, FamilyName, StringComparison.OrdinalIgnoreCase))
                            {
                                FamilyName = elementType.FamilyName;
                            }
                        }

                        var item = new GH_ValueListItem(elementType.FamilyName + " : " + elementType.Name, elementType.Id.IntegerValue.ToString());
                        item.Selected = selectedItems.Contains(item.Expression);
                        ListItems.Add(item);

                        selectedItemsCount += item.Selected ? 1 : 0;
                    }
                }

                // If no selection and we are not in CheckList mode try to select default model types
                if (ListItems.Count == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("No ElementType found using pattern \"{0}\"", FamilyName));
                }
                else if (selectedItemsCount == 0 && ListMode != GH_ValueListMode.CheckList)
                {
                    var defaultElementTypeIds = new HashSet <string>();
                    foreach (var typeGroup in Enum.GetValues(typeof(DB.ElementTypeGroup)).Cast <DB.ElementTypeGroup>())
                    {
                        var elementTypeId = Revit.ActiveDBDocument.GetDefaultElementTypeId(typeGroup);
                        if (elementTypeId != DB.ElementId.InvalidElementId)
                        {
                            defaultElementTypeIds.Add(elementTypeId.IntegerValue.ToString());
                        }
                    }

                    foreach (var item in ListItems)
                    {
                        item.Selected = defaultElementTypeIds.Contains(item.Expression);
                    }
                }
            }
        }
Пример #8
0
        private void RefreshElementTypesList(ListBox listBox, ComboBox categoriesBox, ComboBox familiesBox)
        {
            var doc = Revit.ActiveUIDocument.Document;

            try
            {
                listBox.SelectedIndexChanged -= ElementTypesBox_SelectedIndexChanged;
                listBox.Items.Clear();

                var current = default(Types.ElementType);
                if (SourceCount == 0 && PersistentDataCount == 1)
                {
                    if (PersistentData.get_FirstItem(true) is Types.ElementType firstValue)
                    {
                        current = firstValue as Types.ElementType;
                    }
                }

                {
                    var categories = (
                        categoriesBox.SelectedItem is IGH_GooProxy proxy ?
                        Enumerable.Repeat(proxy, 1) :
                        categoriesBox.Items.OfType <IGH_GooProxy>()
                        ).
                                     Select(x => x.ProxyOwner as Types.Category).
                                     Select(x => x.Id).
                                     ToArray();

                    if (categories.Length > 0)
                    {
                        var elementTypes = default(IEnumerable <DB.ElementId>);
                        using (var collector = new DB.FilteredElementCollector(Revit.ActiveUIDocument.Document))
                        {
                            elementTypes = collector.WhereElementIsElementType().
                                           WherePasses(new DB.ElementMulticategoryFilter(categories)).
                                           ToElementIds();
                        }

                        var familyName = familiesBox.SelectedItem as string;

                        foreach (var elementType in elementTypes)
                        {
                            if
                            (
                                !string.IsNullOrEmpty(familyName) &&
                                doc.GetElement(elementType) is DB.ElementType type &&
                                type.FamilyName != familyName
                            )
                            {
                                continue;
                            }

                            var tag   = Types.ElementType.FromElementId(doc, elementType);
                            int index = listBox.Items.Add(tag.EmitProxy());
                            if (tag.UniqueID == current?.UniqueID)
                            {
                                listBox.SetSelected(index, true);
                            }
                        }
                    }
                }
            }
            finally
            {
                listBox.SelectedIndexChanged += ElementTypesBox_SelectedIndexChanged;
            }
        }