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

 

主站蜘蛛池模板: 成人性生交大片免费看| 成人爽爽激情在线观看| 中文国产成人久久精品小说| 久久精品成人欧美大片免费| 青青草成人影视| 成人午夜视频免费| 免费国产成人手机在线观看| 美国成人免费视频| 成人午夜小视频| 亚洲国产成人久久综合一| 日韩欧美成人免费中文字幕| 国产成人无码av在线播放不卡| 国产成人精品综合在线| 欧美成人一区二区三区在线观看 | 成人免费观看视频高清视频| 免看**一片成人123| 成人毛片免费播放| 1204国产成人精品视频| 国产成人无码专区| 成人白浆超碰人人人人| 亚洲国产精品一区二区成人片国内| 成人欧美一区二区三区在线| 久久成人综合网| 免费观看成人羞羞视频软件 | 亚洲精品午夜国产va久久成人| 成人毛片免费看| 欧美成人久久久| 中文字幕在线成人免费看| 国产91成人精品亚洲精品| 成人小视频在线观看免费| 日韩精品成人一区二区三区| videos欧美成人| 久久亚洲精品成人综合| 国产成人免费午夜在线观看| 国产精品成人99一区无码| 成人激情免费视频| 成人区人妻精品一区二区不卡网站 | 2022国产成人福利精品视频 | 国产成人精品午夜在线播放| 成人性生交大片免费视频| 成人网视频免费播放|