// создание первоначального списка элементов public ObservableCollection <TagItem> tagListData() { IEnumerable <Element> terminal = new FilteredElementCollector(DOC).OfCategory(BuiltInCategory.OST_DuctTerminal) .WhereElementIsNotElementType() .ToElements(); IEnumerable <Element> ductAccessory = new FilteredElementCollector(DOC) .OfCategory(BuiltInCategory.OST_DuctAccessory) .WhereElementIsNotElementType() .ToElements(); IEnumerable <Element> pipeAccessory = new FilteredElementCollector(DOC) .OfCategory(BuiltInCategory.OST_PipeAccessory) .WhereElementIsNotElementType() .ToElements(); IEnumerable <Element> equipment = new FilteredElementCollector(DOC) .OfCategory(BuiltInCategory.OST_MechanicalEquipment) .WhereElementIsNotElementType() .ToElements(); elems = terminal.Union(ductAccessory).Union(pipeAccessory).Union(equipment); ObservableCollection <TagItem> tagItems = new ObservableCollection <TagItem>(); foreach (var e in elems) { string modelTag = e.LookupParameter("TAG")?.AsString(); TagItem t = new TagItem(); t.ModelId = e.Id; t.ModelTag = modelTag; setDraftInfoToTagItem(t, e); tagItems.Add(t); } var groupTagItemsByDraftIds = tagItems.GroupBy(i => i.DraftId); foreach (var g in groupTagItemsByDraftIds) { if (g.Count() > 1 && g.Key != null && g.Key.IntegerValue != -1) { foreach (TagItem t in g) { t.ConnectError = true; } } } tagItems = new ObservableCollection <TagItem>(tagItems.OrderBy(i => i.ItemName)); return(tagItems); }
public void setDraftInfoToTagItem(TagItem t, Element e) { string draftTag = String.Empty; ElementId draftId = getSchemaDictValue <ElementId>(e, "DictElemId", 0) as ElementId; if (draftId != null && draftId.IntegerValue != -1) { draftTag = DOC.GetElement(draftId).LookupParameter("TAG")?.AsString(); } t.DraftId = draftId; t.DraftTag = draftTag; }
//собирает 2 элемента, делает из них новый tagItem public void getTwoElements() { ICollection <ElementId> selectedIds = UIDOC.Selection.GetElementIds(); List <Element> elems = new List <Element>(); if (selectedIds.Count != 2) { IsTwoElementsSelected = false; NewTag = null; } else { foreach (var i in selectedIds) { elems.Add(DOC.GetElement(i)); } if (elems.Any(i => i.Category.Id.IntegerValue != (int)BuiltInCategory.OST_DetailComponents) && elems.Any(i => i.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DetailComponents)) { IsTwoElementsSelected = true; EModel = elems.Where(i => i.Category.Id.IntegerValue != (int)BuiltInCategory.OST_DetailComponents).First(); EDraft = elems.Where(i => i.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DetailComponents).First(); TagItem tag = new TagItem(); tag.ModelId = EModel.Id; tag.DraftId = EDraft.Id; string tagValue = EModel.LookupParameter("TAG").AsString(); tag.ModelTag = tagValue; tag.DraftTag = tagValue; NewTag = tag; } else { IsTwoElementsSelected = false; } } }