Revit二次開發(fā)實(shí)戰(zhàn)04(元素搜集過濾器FilteredElementCollector)|天天新視野

2023-05-21 22:13:29來源:博客園

Revit二次開發(fā)實(shí)戰(zhàn)


(相關(guān)資料圖)

FilteredElementCollector元素搜集過濾器

1、創(chuàng)建搜集器

FilteredElementCollector(Document);搜集文檔中所有元素;

FilteredElementCollector(Document,List);在指定id集合中搜集;

FilteredElementCollector(Document,ElementId viewId);在指定視圖中搜集;

2、調(diào)用過濾函數(shù)

OfCategoryId(newElementId(BuiltInCategory.OST_Doors));

OfCategory(BuiltInCategory.OST_Doors);

OfClass(typeof(Wall));

WherePasses(newRoomFilter());

WherePasses(intersectsFilter);

源碼

using Autodesk.Revit.Attributes;using Autodesk.Revit.DB;using Autodesk.Revit.DB.Architecture;using Autodesk.Revit.UI;using Autodesk.Revit.UI.Selection;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace RevitHello{    [Transaction(TransactionMode.Manual)]    class CElement : IExternalCommand    {        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)        {            //獲取當(dāng)前UI文檔            UIDocument uidoc = commandData.Application.ActiveUIDocument;            //獲取當(dāng)前文檔            Document doc = uidoc.Document;            //創(chuàng)建搜集過濾器            //■構(gòu)造函數(shù)1,搜集文檔中所有元素            FilteredElementCollector collector1 = new FilteredElementCollector(doc);            //按照類別進(jìn)行過濾            FilteredElementCollector filtered1 = collector1.OfCategory(BuiltInCategory.OST_Doors);            ShowElements(filtered1, uidoc, "filtered1");            //選擇多個(gè)對(duì)象,并獲取其id集合            var refs = uidoc.Selection.PickObjects(ObjectType.Element);            List ids = new List();            refs.ToList().ForEach(r => ids.Add(r.ElementId));            //■構(gòu)造函數(shù)2,搜集集合中的元素            FilteredElementCollector collector2 = new FilteredElementCollector(doc, ids);            //按照類別Id進(jìn)行過濾 所有的門            FilteredElementCollector filtered2 = collector2.OfCategoryId(new ElementId(BuiltInCategory.OST_Doors));            ShowElements(filtered2, uidoc, "filtered2");            //獲取當(dāng)前文檔的當(dāng)前視圖            View view = uidoc.ActiveView;            //■構(gòu)造函數(shù)3,搜集視圖中的元素            FilteredElementCollector collector3 = new FilteredElementCollector(doc, view.Id);            //按照class的Type類型進(jìn)行過濾            FilteredElementCollector filtered3 = collector3.OfClass(typeof(Wall));            ShowElements(filtered3, uidoc, "filtered3");            FilteredElementCollector collector4 = new FilteredElementCollector(doc);            List filtered4 = collector4.WherePasses(new RoomFilter()).Cast().ToList();            ShowElements(filtered4, uidoc, "filtered4");            //獲取一個(gè)包圍盒,并過濾出與該包圍盒相交的元素            var refe = uidoc.Selection.PickObject(ObjectType.Element, new DoorSelectionFilter());            var ele = doc.GetElement(refe);            var box = ele.get_BoundingBox(view);            BoundingBoxIntersectsFilter intersectsFilter = new BoundingBoxIntersectsFilter(new Outline(box.Min, box.Max));            FilteredElementCollector collector5 = new FilteredElementCollector(doc);            var filtered5 = collector5.WherePasses(intersectsFilter).ToElements();            ShowElements(filtered5, uidoc, "filtered5");            return Result.Succeeded;        }        //把輸出元素集合信息封裝成一個(gè)函數(shù)        void ShowElements(IEnumerable elements, UIDocument uidoc, string title)        {                      StringBuilder sb = new StringBuilder();            sb.AppendLine($"Count={elements.Count()}");            List ids = new List();            elements.ToList().ForEach((e) =>            {                sb.AppendLine($"Id={e.Id},Name={e.Name},Category={e.Category.Name}");                ids.Add(e.Id);            });            //高亮顯示所有過濾的對(duì)象            uidoc.Selection.SetElementIds(ids);            //對(duì)話框顯示所有過濾對(duì)象的信息            TaskDialog.Show(title, sb.ToString());        }    }    class DoorSelectionFilter : ISelectionFilter    {        public bool AllowElement(Element elem)        {            if (elem.Category.Id.IntegerValue==(int)BuiltInCategory.OST_Doors) return true;            return false;        }        public bool AllowReference(Reference reference, XYZ position)        {            return true;        }    }}

關(guān)鍵詞:

責(zé)任編輯:孫知兵

免責(zé)聲明:本文僅代表作者個(gè)人觀點(diǎn),與太平洋財(cái)富網(wǎng)無關(guān)。其原創(chuàng)性以及文中陳述文字和內(nèi)容未經(jīng)本站證實(shí),對(duì)本文以及其中全部或者部分內(nèi)容、文字的真實(shí)性、完整性、及時(shí)性本站不作任何保證或承諾,請(qǐng)讀者僅作參考,并請(qǐng)自行核實(shí)相關(guān)內(nèi)容。
如有問題,請(qǐng)聯(lián)系我們!

關(guān)于我們 - 聯(lián)系方式 - 版權(quán)聲明 - 招聘信息 - 友鏈交換 - 網(wǎng)站統(tǒng)計(jì)
 

太平洋財(cái)富主辦 版權(quán)所有:太平洋財(cái)富網(wǎng)

?中國互聯(lián)網(wǎng)違法和不良信息舉報(bào)中心中國互聯(lián)網(wǎng)違法和不良信息舉報(bào)中心

Copyright© 2012-2020 太平洋財(cái)富網(wǎng)(www.8899ip.com) All rights reserved.

未經(jīng)過本站允許 請(qǐng)勿將本站內(nèi)容傳播或復(fù)制 業(yè)務(wù)QQ:3 31 986 683

 

主站蜘蛛池模板: 久久亚洲国产成人精品无码区 | 91亚洲国产成人久久精品网站| 成人综合视频网| 成人免费看黄20分钟| 成人毛片免费视频播放| 91成人午夜在线精品| 国产成人精品怡红院在线观看| 国产成人综合久久综合| 成人欧美在线视频| 国产成人精品999在线| 亚洲午夜成人片| 成人无码免费一区二区三区| 国产成人久久精品二区三区| 国产成人无码精品久久久免费 | 欧美成人一区二区三区在线视频 | 亚洲国产精品成人久久| 在线观看国产精成人品| 天天摸夜夜摸成人免费视频| 中文字幕成人免费高清在线| 成人午夜精品视频在线观看| 国产成人久久精品二区三区| 国产成人免费av片在线观看| 久久久久亚洲av成人网| av成人在线电影| 亚洲欧美成人综合久久久| 国产成人高清精品免费鸭子| 日韩av无码成人精品国产| 亚洲国产成人精品女人久久久 | 免费成人一级片| 亚洲国产成人精品激情| 成人精品视频一区二区三区尤物| 亚洲精品无码乱码成人| 免费无码成人AV片在线在线播放| 成人做受视频试看60秒| 日韩欧美成人乱码一在线 | 亚洲精品成人网站在线播放| 亚洲色成人www永久网站| 国产精品成人无码免费| 国产精品成人亚洲| 四虎亚洲国产成人久久精品| 国产成人亚洲综合无码|