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在线播放不卡| 成人免费视频观看无遮挡| 成人免费无遮挡无码黄漫视频| 国内成人精品亚洲日本语音| 国产一区亚洲欧美成人| 欧洲成人r片在线观看| 亚洲精品无码乱码成人| 成人午夜在线视频| 九九精品免视看国产成人| 国产成人高清在线播放| 香蕉久久久久久AV成人| 国产成人精品999在线观看| 欧美成人看片一区二区三区尤物 | 成人欧美一区二区三区视频| 国产成人免费观看| 成人免费看www网址入口| 2022国产成人精品福利网站| 国产成人精品久久综合| 成人羞羞视频在线观看| 久久久久亚洲AV成人网| 四虎高清成人永久免费影院| 成人免费网站视频www| 成人在线综合网| 成人免费观看一区二区| 成人免费无码大片a毛片软件| 欧美成人免费一区在线播放| 精品无码成人久久久久久| 亚洲AV无码成人专区| 亚洲成人自拍网| 亚洲精品成人a在线观看| 国产成人涩涩涩视频在线观看免费| 成人午夜视频免费看欧美| 成人国产精品视频| 国产精品成人免费福利| 国产成人在线网站| 亚洲高清成人欧美动作片| 亚洲人成人77777网站| 久久久99精品成人片中文字幕 | 亚洲国产成人99精品激情在线| 久久亚洲国产精品成人AV秋霞|