Revit二次開發(fā)實(shí)戰(zhàn)04(元素搜集過濾器FilteredElementCollector)|天天新視野
Revit二次開發(fā)實(shí)戰(zhàn)
(相關(guān)資料圖)
FilteredElementCollector元素搜集過濾器
1、創(chuàng)建搜集器 | FilteredElementCollector(Document);搜集文檔中所有元素; FilteredElementCollector(Document,List 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)系我們!
- Revit二次開發(fā)實(shí)戰(zhàn)04(元素搜集過濾器Filte2023-05-21
- 永善枇杷節(jié)丨380余人參與“登頂玉筍”健身2023-05-21
- 今年滬深股市中科技類股票有哪些?2023-05-21
- 啤酒洗頭有什么好處(啤酒洗頭有什么好處)_2023-05-21
- 重點(diǎn)聚焦!深藍(lán)汽車推出首款SUV——深藍(lán)S7 2023-05-21
- 東望時(shí)代:前4月合并營(yíng)業(yè)收入同比增加125.26%2023-05-21
- 世界即時(shí):冠農(nóng)股份入選2023年度鄭商所“服2023-05-21
- 虎婚姻跟什么屬相更好,屬相婚姻準(zhǔn)嗎2023-05-21
- 遼寧沖三連冠穩(wěn)了?曝周琦已獲1億報(bào)價(jià) 北2023-05-21
- 鈣吸收不好是什么原因(影響鈣吸收的因素有2023-05-21
- 珀萊雅:4月主品牌天貓旗艦店成交金額增長(zhǎng)52023-05-21
- 【環(huán)球新視野】長(zhǎng)沙橘子洲舉辦公益跑助力12023-05-21
- 環(huán)球動(dòng)態(tài):硬核科技論 | 為什么說油電混動(dòng)2023-05-21
- 全球動(dòng)態(tài):一波強(qiáng)降雨來襲!省防指會(huì)商部署2023-05-21
- 天天視點(diǎn)!指南針軟件怎么快速找到出現(xiàn)三把2023-05-21
- 什么叫序數(shù)(什么是奇數(shù)什么是序數(shù)?)|全球2023-05-21
- 快消息!龍?bào)纯萍迹?月酸鐵鋰正極材料出貨2023-05-21
- 貝克漢姆與拉什福德在推特上互動(dòng)2023-05-21
- 慘!4月合資SUV銷量榜,僅8款車破萬輛,奔2023-05-21
- *ST紫鑫:存在可能因股價(jià)低于面值被終止上2023-05-21
- 中證指數(shù)有限公司:聚焦能源安全、數(shù)字經(jīng)濟(jì)2023-05-21
- 【獨(dú)家】狗狗尿道流膿吃什么藥(狗狗尿道感2023-05-21
- 金斯瑞生物科技:傳奇生物向高瓴投資定向增2023-05-21
- 今日最新!海明威吞槍自殺(關(guān)于海明威吞槍2023-05-21
- 彤管有煒造句_彤管有煒-焦點(diǎn)報(bào)道2023-05-21
- 世界最新:電動(dòng)3號(hào):日產(chǎn)艾睿雅2023-05-21
- 考研abc區(qū)有什么區(qū)別2023-05-21
- 天天快報(bào)!港股可以通過哪些證券公司購買2023-05-21
- 隱形牙套什么樣(隱形牙套的優(yōu)缺點(diǎn)是什么?2023-05-21
- 格力電器董明珠:讓世界愛上中國造-環(huán)球熱2023-05-21
精彩推薦
- Revit二次開發(fā)實(shí)戰(zhàn)04(元素搜集過濾器Fi...
- 遼寧沖三連冠穩(wěn)了?曝周琦已獲1億報(bào)價(jià) ...
- 環(huán)球動(dòng)態(tài):硬核科技論 | 為什么說油電...
- 慘!4月合資SUV銷量榜,僅8款車破萬輛,...
- 彤管有煒造句_彤管有煒-焦點(diǎn)報(bào)道
- 怒喵 CYBERBLADE 耳機(jī)降至 1480 元...
- 5年期LPR超預(yù)期下調(diào)15個(gè)基點(diǎn),今日之后...
- 長(zhǎng)征七號(hào)遙七運(yùn)載火箭二級(jí)殘骸已再入大...
- 房屋轉(zhuǎn)讓合同協(xié)議書范本_土地轉(zhuǎn)讓合同范...
- 油菜的花樣吃法,食譜不再單調(diào)
- 報(bào)考駕校請(qǐng)先看!武漢最新駕校“紅黑榜...
- 最新快訊!2023年河南安陽市第三中學(xué)藝術(shù)...
- 甘肅省新能源產(chǎn)業(yè)招商推介會(huì)在成都舉辦
- 饅頭怎么保存才能保存長(zhǎng)久 饅頭如何儲(chǔ)...
- 車險(xiǎn)不計(jì)免賠取消了三者險(xiǎn)(車險(xiǎn)不計(jì)免...