简单的方法收集特定视图(Revit二次开发)

我们在写功能的时候,会遇到需要收集特定的平面视图的情况。

比如说搜集楼层平面视图,通常的操作就是写一个方法,先收集所有的ViewPlan,然后再通过ViewFamilyType的名称去判断是不是楼层平面视图。

常规方法

public List<ViewPlan> GetFloorViewPlan(Document doc){FilteredElementCollector collector = new FilteredElementCollector(doc);//过滤出视图collector.OfCategory(BuiltInCategory.OST_Views).OfClass(typeof(ViewPlan));List<ViewPlan> floorPlan = new List<ViewPlan>();//遍历视图foreach (ViewPlan ele in collector){//获取视图的ViewFamilyTypeViewFamilyType familyType = doc.GetElement(ele.GetTypeId()) as ViewFamilyType;//过滤null值留下ViewFamily.FloorPlan的值if (familyType == null) continue;if (familyType.ViewFamily == ViewFamily.FloorPlan)floorPlan.Add(ele);}return floorPlan;}

但是由于收集到的ViewPlan中包括太多种视图类型,这样子会大大的提高了我们的运行的循环的次数,也增加代码量。因此,我们完全可以在一开始收集ViewPlan的时候,直接加上一个ViewPlan的ViewFamily类型的判断。

ViewFamiiy枚举值

Member nameDescription翻译
InvalidInvalid view type无效视图类型
ThreeDimensional3D view3D视图
WalkthroughWalkthrough view漫游视图
ImageViewRendering view渲染视图
ScheduleSchedule view明细表视图
CostReportCost report view (obsolete)成本报告视图(已过时)
SheetSheet view图纸视图
DraftingDrafting view草稿视图
FloorPlanFloor plan view楼层平面图
AreaPlanArea plan view区域平面图
CeilingPlanCeiling plan view天花板平面图
SectionSection view剖面图
DetailDetail view局部详图
ElevationElevation view立面视图(高程视图)
LoadsReportHVAC load report暖通空调负荷报告
PressureLossReportPressure loss report压力损失报告
LegendLegend view图例视图
PanelSchedulePanel schedule配电盘明细表
GraphicalColumnScheduleGraphical column schedule图形列时间表
StructuralPlanStructural plan view结构平面图

ViewFamily枚举中提供了所有视图的枚举类型,其中有我们常用的ThreeDimensional(三维视图)、FloorPlan(楼层平面视图)、CeilingPlan(天花板平面视图)。

因此我们可以这样去收集楼层平面视图:

List<ViewPlan> floorPlan = new FilteredElementCollector(doc).OfClass(typeof(ViewPlan)).Where
(x => (doc.GetElement(x.GetTypeId()) as ViewFamilyType).ViewFamily 
== ViewFamily.FloorPlan).Cast<ViewPlan>().ToList();

经过测试,该方法可能产生null值,
而且应为语句高度集中,会导致后期调试特别麻烦,所以还是不推荐使用此方法。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部