protected void ElementSetName(Types.Element element, string value)
        {
            if (TransactionExtent == TransactionExtent.Component)
            {
                if (string.IsNullOrEmpty(value))
                {
                    return;
                }

                if (renames is null)
                {
                    renames = new Dictionary <Types.Element, string>();
                }

                if (renames.TryGetValue(element, out var name))
                {
                    if (name == value)
                    {
                        return;
                    }

                    renames.Remove(element);
                }
                else
                {
                    element.Name = Guid.NewGuid().ToString();
                }

                renames.Add(element, value);
            }
            else
            {
                element.Name = value;
            }
        }
Exemple #2
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);
                    }
                }
            }
        }
Exemple #3
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 != null)
            {
                int selectedItemsCount = 0;
                using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument))
                    using (var elementTypeCollector = collector.WhereElementIsElementType())
                    {
                        foreach (var goo in goos)
                        {
                            var e = new Types.Element();
                            if (e.CastFrom(goo))
                            {
                                switch ((Autodesk.Revit.DB.Element)e)
                                {
                                case Autodesk.Revit.DB.Family family:
                                    foreach (var elementType in elementTypeCollector.Cast <Autodesk.Revit.DB.ElementType>())
                                    {
                                        if (elementType.FamilyName != family.Name)
                                        {
                                            continue;
                                        }

                                        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;
                                    }
                                    break;

                                case Autodesk.Revit.DB.ElementType elementType:
                                {
                                    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;
                                }
                                break;

                                case Autodesk.Revit.DB.Element element:
                                {
                                    var type = Revit.ActiveDBDocument.GetElement(element.GetTypeId()) as Autodesk.Revit.DB.ElementType;
                                    var item = new GH_ValueListItem(type.FamilyName + " : " + type.Name, type.Id.IntegerValue.ToString());
                                    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.OfCategoryId(c.Value).Cast <Autodesk.Revit.DB.ElementType>())
                                    {
                                        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;
                                    }
                                }
                                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(ElementTypeGroup)).Cast <ElementTypeGroup>())
                    {
                        var elementTypeId = Revit.ActiveDBDocument.GetDefaultElementTypeId(typeGroup);
                        if (elementTypeId != ElementId.InvalidElementId)
                        {
                            defaultElementTypeIds.Add(elementTypeId.IntegerValue.ToString());
                        }
                    }

                    foreach (var item in ListItems)
                    {
                        item.Selected = defaultElementTypeIds.Contains(item.Expression);
                    }
                }
            }
        }