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毛片| 777奇米四色成人影视色区| 亚洲国产精品成人AV在线| 四虎www成人影院| 欧美国产成人精品一区二区三区| 日韩精品成人一区二区三区| 国产成人综合久久精品免费| 国产成人cao在线| 2022国产成人精品视频人| 日韩成人免费在线| 国产成人亚洲精品无码青青草原| 亚洲国产成人精品无码一区二区| 欧美成人免费观看久久| 亚洲欧美成人综合| 国内外成人免费视频| 精品久久久久成人码免费动漫| 国产成人一区二区三区精品久久| 成人秋霞在线观看视频| 亚洲成人免费网站| 国产成人无码AV一区二区| 成人免费草草视频| 成人福利app| 成人看片黄a免费看| 亚洲精品国产成人| 国产成人亚洲综合在线| 国产精品成人第一区| 成人无码免费一区二区三区| 99国产精品久久久久久久成人热 | 国产成人高清精品免费软件| 窝窝视频成人影院午夜在线| 久久久久亚洲AV成人网人人网站| 国产成人3p视频免费观看| 国产成人无码av| 四虎影视成人永久免费观看视频| 国产成人高清亚洲一区app| 成人午夜看片在线观看| 大臿蕉香蕉大视频成人| 国产成人精品综合在线观看| 国产成人免费网站| 国产乱色精品成人免费视频| 全球中文成人在线|