示例#1
0
        // The action function for ConnectButtonAction
        /// <summary>
        /// Если в списке уже есть tagItem с таким ТЭГом, то заменяем его, если нет - добавляем в список
        /// </summary>
        private void ConnectButtonAction()
        {
            RevitModel.getTwoElements();

            if (RevitModel.IsTwoElementsSelected)
            {
                connectEvent.Raise();
                int idx;

                if (NewTag != null)
                {
                    //внесение правки в существующий элемент списка или добавление нового
                    if (TagItems.Any(i => i.ModelId == NewTag.ModelId))
                    {
                        TagItem t = TagItems.Where(i => i.ModelId == NewTag.ModelId).First();
                        idx           = TagItems.IndexOf(t);
                        TagItems[idx] = NewTag;
                    }
                    else
                    {
                        TagItems.Add(NewTag);
                    }
                }
            }
        }
示例#2
0
        // создание первоначального списка элементов
        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);
        }
示例#3
0
        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;
        }
示例#4
0
        //собирает 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;
                }
            }
        }