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)(m.8899ip.com) All rights reserved.

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

 

主站蜘蛛池模板: 国产成人黄网在线免| 成人超污免费网站在线看| 国产成人无码AⅤ片在线观看| 成人黄色免费网址| 国产成人精品日本亚洲| 亚洲a级成人片在线观看| 国产成人精品电影| 国产成人精品一区二三区在线观看 | 我的初次内射欧美成人影视| 欧美成人精品福利网站| 色欲欲WWW成人网站| 成人在线免费看| 国产成人国产在线观看入口| a级成人毛片完整版| 小明发布永久在线成人免费| 亚洲国产成人精品青青草原| 国产精品成人免费视频网站| 78成人精品电影在线播放 | 成人18免费网站在线观看| 欧美成人免费全部观看在线看 | 四虎成人免费大片在线| 欧美成人怡红院在线观看| 国产成人精品无码一区二区老年人 | 成人网站免费看黄a站视频| 日韩成人在线网站| 免看**一片成人123| 欧美成人免费高清网站| 亚洲最大成人网色| 欧美成人18性| 亚洲第一成人在线| 成人欧美一区二区三区在线观看 | 免费网站看v片在线成人国产系列| 日本成人在线视频网站| 成人午夜国产内射主播| 中文字幕在线看片成人| 国产成人久久久精品二区三区| 成人精品一区二区三区中文字幕| 久久亚洲国产精品成人AV秋霞| 亚洲精品国产成人| 久久亚洲国产成人精品无码区| 亚洲精品亚洲人成人网|