Revit单构件导出IFC

对revit模型的应用中,由于模型过大,不得不进行模型拆分导出。本文针对模型单构件导出ifc,写了个小功能。revit支持只仅导出视图可见的模型,窗口操作如下图:

我们要用代码实现上述功能。
revit提供API用于导出IFC,是IFCExportOption,其中的AddOption(string name,string value)方法的参数name和value,是指导出option的name,以及相应的值,代码如下:

 public  static Result ExportToIfc(UIDocument uidoc,  Transaction transaction, string name, string Path){transaction.Start();Result r = Result.Failed;IFCExportOptions opt = new IFCExportOptions();opt.ExportBaseQuantities = true;// ExporterIFC exporter;opt.FilterViewId = uidoc.ActiveView.Id;//  exporter.GetOptions();opt.FileVersion = IFCVersion.IFC2x3;opt.AddOption("ExportIFCCommonPropertySets", true.ToString());opt.AddOption("UseActiveViewGeometry",true.ToString());// opt.AddOption("ExportVisibleElementsInView",true.ToString());//  opt.AddOption("Export only elements visible in view", true.ToString());opt.AddOption("TessellationLevelOfDetail", "0");opt.AddOption("ActiveViewId", uidoc.ActiveView.Id.ToString());uidoc.Document.Export(Path, name, opt);          transaction.Commit();r = Result.Succeeded;          return r;}#endregion

首先利用过滤器过滤项目中的全部构件(类别可能还是不全,根据需求调整):

  #region 过滤构件//获取墙FilteredElementCollector CollectionWall = new FilteredElementCollector(doc, viewId);//    ElementFilter filterWall = new ElementCategoryFilter(BuiltInCategory.OST_Walls);ICollection<Element> eleWalls = CollectionWall.OfClass(typeof(Wall)).ToElements().ToList();elementList.AddRange(eleWalls);//风管FilteredElementCollector CollectionDuct = new FilteredElementCollector(doc, viewId);ICollection<Element> eleDucts = CollectionDuct.OfClass(typeof(Duct)).ToElements();elementList.AddRange(eleDucts);//获取自建族实例FilteredElementCollector CollectionFamIns = new FilteredElementCollector(doc, viewId);ICollection<Element> eleFamIns = CollectionFamIns.OfClass(typeof(FamilyInstance)).ToElements();elementList.AddRange(eleFamIns);//屋顶 roofFilteredElementCollector CollectionRoof = new FilteredElementCollector(doc, viewId);ICollection<Element> eleRoof = CollectionRoof.OfClass(typeof(RoofType)).ToElements();elementList.AddRange(eleRoof);//天花板 ceilingFilteredElementCollector CollectionCeil = new FilteredElementCollector(doc, viewId);ICollection<Element> eleCeil = CollectionCeil.OfClass(typeof(Ceiling)).ToElements();elementList.AddRange(eleCeil);//楼板 FloorFilteredElementCollector CollectionFloor = new FilteredElementCollector(doc, viewId);ICollection<Element> eleFloor = CollectionFloor.OfClass(typeof(Floor)).ToElements();elementList.AddRange(eleFloor);//管道 pipeFilteredElementCollector CollectionPipe = new FilteredElementCollector(doc, viewId);ICollection<Element> elePipe = CollectionPipe.OfClass(typeof(Pipe)).ToElements();elementList.AddRange(elePipe);//电缆桥架 CabletrayFilteredElementCollector CollectionCabletray = new FilteredElementCollector(doc, viewId);List<Element> eleCable = CollectionCabletray.OfClass(typeof(CableTray)).ToElements().ToList();elementList.AddRange(eleCable);//线管 conduitFilteredElementCollector CollectionCond = new FilteredElementCollector(doc, viewId);ICollection<Element> eleCond = CollectionCond.OfClass(typeof(Conduit)).ToElements();elementList.AddRange(eleCond);//楼梯  stair//FilteredElementCollector CollectionStair = new FilteredElementCollector(doc, viewId);//ICollection<Element> eleStair = CollectionStair.OfClass(typeof(Stairs)).ToElements();//elementList.AddRange(eleStair);//扶手 railingFilteredElementCollector CollectionRail = new FilteredElementCollector(doc, viewId);ICollection<Element> eleRail = CollectionRail.OfClass(typeof(Railing)).ToElements();elementList.AddRange(eleRail);//扶手顶端 toprailingFilteredElementCollector CollectionTopRail = new FilteredElementCollector(doc, viewId);ICollection<Element> eleTopRail = CollectionTopRail.OfClass(typeof(TopRail)).ToElements();elementList.AddRange(eleTopRail);//梁(beam和FamilySymbol类型)FilteredElementCollector CollectionBeam = new FilteredElementCollector(doc, viewId);ICollection<Element> eleBeam = CollectionBeam.OfClass(typeof(BeamSystem)).ToElements();elementList.AddRange(eleBeam);//幕墙竖梃FilteredElementCollector CollectionMullion = new FilteredElementCollector(doc, viewId);ICollection<Element> eleMullion = CollectionMullion.OfClass(typeof(MullionType)).ToElements();elementList.AddRange(eleMullion);其他 family类型FilteredElementCollector CollectionFamily = new FilteredElementCollector(doc);ICollection<Element> eleFamily = CollectionRail.OfClass(typeof(Family)).ToElements();elementList.AddRange(eleFamily);// 其他 Element//FilteredElementCollector CollectionElement = new FilteredElementCollector(doc);//ICollection<Element> eleElement = CollectionElement.OfClass(typeof(ElementType)).ToElements();//elementList.AddRange(eleElement);//TaskDialog.Show("提示", "Element:" + eleElement.Count);#region Category针对性分类//其他读不到的针对性分类element类型(楼梯)FilteredElementCollector CollectionStairs = new FilteredElementCollector(doc, viewId);ElementFilter StairsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs);ICollection<Element> eleStairs = CollectionStairs.WherePasses(StairsFilter).ToElements();elementList.AddRange(eleStairs);//坡道FilteredElementCollector CollectionRamps = new FilteredElementCollector(doc, viewId);ElementFilter RampsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Ramps);ICollection<Element> eleRamps = CollectionRamps.WherePasses(RampsFilter).ToElements();elementList.AddRange(eleRamps);//洞口截面FilteredElementCollector CollectionCeilingOpening = new FilteredElementCollector(doc, viewId);ElementFilter CeilingOpeningFilter = new ElementCategoryFilter(BuiltInCategory.OST_CeilingOpening);ICollection<Element> eleCeilingOpening = CollectionCeilingOpening.WherePasses(CeilingOpeningFilter).ToElements();elementList.AddRange(eleCeilingOpening);//Group类型FilteredElementCollector CollectionGroup = new FilteredElementCollector(doc, viewId);          ElementFilter GroupFilter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups);ICollection<Element> eleGroup = CollectionGroup.WherePasses(GroupFilter).ToElements();elementList.AddRange(eleGroup);Panel类型//FilteredElementCollector CollectionPanel = new FilteredElementCollector(doc, viewId);//ElementFilter PanelFilter = new ElementCategoryFilter(BuiltInCategory.OST_CurtainWallPanels);//ICollection<Element> elePanel = CollectionPanel.WherePasses(PanelFilter).ToElements();//elementList.AddRange(elePanel);//TaskDialog.Show("提示", "panel:" + elePanel.Count);#endregion

导出时用隐藏模型,仅导出视图可见模型:

 #region 隐藏构件导出模型Transaction tr = new Transaction(doc, "tr");Transaction tran = new Transaction(doc, "tran");View view = uidoc.ActiveView;foreach (Element element in elementList){List<ElementId> HideShowEleIds = new List<ElementId>();tr.Start();ElementId e = viewId;foreach (ElementId elementId in elementIdList){if (elementId == element.Id){e = elementId;}else{HideShowEleIds.Add(elementId);}}view.HideElements(HideShowEleIds);string  name = element.Id.ToString();tr.Commit();ExportToIfc(uidoc, tr, element.Id.ToString(), Path);tran.Start();view.UnhideElements(HideShowEleIds);tran.Commit();}#endregion

整个代码为:

using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.IFC;
using Autodesk.Revit.DB.ExternalService;
using Autodesk.Revit.DB.Events;namespace IFCExport
{[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]public class Class1 : IExternalCommand{#regionpublic Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){UIApplication uiapp = commandData.Application;UIDocument uidoc = uiapp.ActiveUIDocument;Document doc = uidoc.Document;ElementId viewId = uidoc.ActiveView.Id;List<Element> elementList = new List<Element>();List<ElementId> elementIdList = new List<ElementId>();string Path = "";System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();dialog.Description = "请选择ifc的目标文件夹";if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){if (string.IsNullOrEmpty(dialog.SelectedPath)){TaskDialog.Show("提示", "路径不能为空!");}else{Path = dialog.SelectedPath;}}#region 过滤构件//获取墙FilteredElementCollector CollectionWall = new FilteredElementCollector(doc, viewId);//    ElementFilter filterWall = new ElementCategoryFilter(BuiltInCategory.OST_Walls);ICollection<Element> eleWalls = CollectionWall.OfClass(typeof(Wall)).ToElements().ToList();elementList.AddRange(eleWalls);//风管FilteredElementCollector CollectionDuct = new FilteredElementCollector(doc, viewId);ICollection<Element> eleDucts = CollectionDuct.OfClass(typeof(Duct)).ToElements();elementList.AddRange(eleDucts);//获取自建族实例FilteredElementCollector CollectionFamIns = new FilteredElementCollector(doc, viewId);ICollection<Element> eleFamIns = CollectionFamIns.OfClass(typeof(FamilyInstance)).ToElements();elementList.AddRange(eleFamIns);//屋顶 roofFilteredElementCollector CollectionRoof = new FilteredElementCollector(doc, viewId);ICollection<Element> eleRoof = CollectionRoof.OfClass(typeof(RoofType)).ToElements();elementList.AddRange(eleRoof);//天花板 ceilingFilteredElementCollector CollectionCeil = new FilteredElementCollector(doc, viewId);ICollection<Element> eleCeil = CollectionCeil.OfClass(typeof(Ceiling)).ToElements();elementList.AddRange(eleCeil);//楼板 FloorFilteredElementCollector CollectionFloor = new FilteredElementCollector(doc, viewId);ICollection<Element> eleFloor = CollectionFloor.OfClass(typeof(Floor)).ToElements();elementList.AddRange(eleFloor);//管道 pipeFilteredElementCollector CollectionPipe = new FilteredElementCollector(doc, viewId);ICollection<Element> elePipe = CollectionPipe.OfClass(typeof(Pipe)).ToElements();elementList.AddRange(elePipe);//电缆桥架 CabletrayFilteredElementCollector CollectionCabletray = new FilteredElementCollector(doc, viewId);List<Element> eleCable = CollectionCabletray.OfClass(typeof(CableTray)).ToElements().ToList();elementList.AddRange(eleCable);//线管 conduitFilteredElementCollector CollectionCond = new FilteredElementCollector(doc, viewId);ICollection<Element> eleCond = CollectionCond.OfClass(typeof(Conduit)).ToElements();elementList.AddRange(eleCond);//楼梯  stair//FilteredElementCollector CollectionStair = new FilteredElementCollector(doc, viewId);//ICollection<Element> eleStair = CollectionStair.OfClass(typeof(Stairs)).ToElements();//elementList.AddRange(eleStair);//扶手 railingFilteredElementCollector CollectionRail = new FilteredElementCollector(doc, viewId);ICollection<Element> eleRail = CollectionRail.OfClass(typeof(Railing)).ToElements();elementList.AddRange(eleRail);//扶手顶端 toprailingFilteredElementCollector CollectionTopRail = new FilteredElementCollector(doc, viewId);ICollection<Element> eleTopRail = CollectionTopRail.OfClass(typeof(TopRail)).ToElements();elementList.AddRange(eleTopRail);//梁(beam和FamilySymbol类型)FilteredElementCollector CollectionBeam = new FilteredElementCollector(doc, viewId);ICollection<Element> eleBeam = CollectionBeam.OfClass(typeof(BeamSystem)).ToElements();elementList.AddRange(eleBeam);//幕墙竖梃FilteredElementCollector CollectionMullion = new FilteredElementCollector(doc, viewId);ICollection<Element> eleMullion = CollectionMullion.OfClass(typeof(MullionType)).ToElements();elementList.AddRange(eleMullion);其他 family类型FilteredElementCollector CollectionFamily = new FilteredElementCollector(doc);ICollection<Element> eleFamily = CollectionRail.OfClass(typeof(Family)).ToElements();elementList.AddRange(eleFamily);// 其他 Element//FilteredElementCollector CollectionElement = new FilteredElementCollector(doc);//ICollection<Element> eleElement = CollectionElement.OfClass(typeof(ElementType)).ToElements();//elementList.AddRange(eleElement);//TaskDialog.Show("提示", "Element:" + eleElement.Count);#region Category针对性分类//其他读不到的针对性分类element类型(楼梯)FilteredElementCollector CollectionStairs = new FilteredElementCollector(doc, viewId);ElementFilter StairsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs);ICollection<Element> eleStairs = CollectionStairs.WherePasses(StairsFilter).ToElements();elementList.AddRange(eleStairs);//坡道FilteredElementCollector CollectionRamps = new FilteredElementCollector(doc, viewId);ElementFilter RampsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Ramps);ICollection<Element> eleRamps = CollectionRamps.WherePasses(RampsFilter).ToElements();elementList.AddRange(eleRamps);//洞口截面FilteredElementCollector CollectionCeilingOpening = new FilteredElementCollector(doc, viewId);ElementFilter CeilingOpeningFilter = new ElementCategoryFilter(BuiltInCategory.OST_CeilingOpening);ICollection<Element> eleCeilingOpening = CollectionCeilingOpening.WherePasses(CeilingOpeningFilter).ToElements();elementList.AddRange(eleCeilingOpening);//Group类型FilteredElementCollector CollectionGroup = new FilteredElementCollector(doc, viewId);          ElementFilter GroupFilter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups);ICollection<Element> eleGroup = CollectionGroup.WherePasses(GroupFilter).ToElements();elementList.AddRange(eleGroup);Panel类型//FilteredElementCollector CollectionPanel = new FilteredElementCollector(doc, viewId);//ElementFilter PanelFilter = new ElementCategoryFilter(BuiltInCategory.OST_CurtainWallPanels);//ICollection<Element> elePanel = CollectionPanel.WherePasses(PanelFilter).ToElements();//elementList.AddRange(elePanel);//TaskDialog.Show("提示", "panel:" + elePanel.Count);#endregion#endregion//遍历element foreach (var ele in elementList){               //  FamilyInstance fam = ele as FamilyInstance;if (ele != null && !(ele is Panel)){                    elementIdList.Add(ele.Id);}}#region 隐藏构件导出模型Transaction tr = new Transaction(doc, "tr");Transaction tran = new Transaction(doc, "tran");Transaction transaction = new Transaction(doc,"delect");View view = uidoc.ActiveView;foreach (Element element in elementList){List<ElementId> HideShowEleIds = new List<ElementId>();tr.Start();ElementId e = viewId;foreach (ElementId elementId in elementIdList){if (elementId == element.Id){e = elementId;}else{HideShowEleIds.Add(elementId);}}view.HideElements(HideShowEleIds);string  name = element.Id.ToString();tr.Commit();ExportToIfc(uidoc, tr, element.Id.ToString(), Path);tran.Start();view.UnhideElements(HideShowEleIds);tran.Commit();transaction.Start();elementIdList.Remove(element.Id);doc.Delete(element.Id);transaction.Commit();}#endregionreturn Result.Succeeded;}#endregion#region exportToifcpublic  static Result ExportToIfc(UIDocument uidoc,  Transaction transaction, string name, string Path){transaction.Start();Result r = Result.Failed;IFCExportOptions opt = new IFCExportOptions();opt.ExportBaseQuantities = true;// ExporterIFC exporter;opt.FilterViewId = uidoc.ActiveView.Id;//  exporter.GetOptions();opt.FileVersion = IFCVersion.IFC2x3;opt.AddOption("ExportIFCCommonPropertySets", true.ToString());opt.AddOption("UseActiveViewGeometry",true.ToString());// opt.AddOption("ExportVisibleElementsInView",true.ToString());//  opt.AddOption("Export only elements visible in view", true.ToString());opt.AddOption("TessellationLevelOfDetail", "0");opt.AddOption("ActiveViewId", uidoc.ActiveView.Id.ToString());uidoc.Document.Export(Path, name, opt);          transaction.Commit();r = Result.Succeeded;return r;}#endregion }
}

Revit单构件导出IFC相关推荐

  1. revit 转换ifc_Revit导出ifc步骤有哪些?Revit 模型导出 .exe 脱机文件的方法步骤

    文章来源:FreeBIM 序言 大家在做项目的时候是不是遇到过这种情况,自己辛辛苦苦做了一个很好的Revit模型(尤其是精装修项目)需要给客户展示交付或者单纯自己想给亲朋好友嘚瑟一下,这个时候会面临一 ...

  2. 如何使用FME在Revit中导出IFC

    如何使用FME在Revit中导出IFC 原文地址: https://community.safe.com/s/article/how-to-use-fme-exporter-for-revit 一.简 ...

  3. 建模步骤_Revit软件介绍?Revit参数化构件建模步骤

    Revit软件介绍?Revit参数化构件建模步骤!Revit是Autodesk公司旗下一款服务于建筑信息模型(BIM)的软件,旨在帮助使用者设计.建造.维护质量更好.效能更高的建筑.Revit中的所有 ...

  4. [Revit教程]斑马:分享一个用Revit自适应构件做安全疏散距离分析的方法#S007

    摘要:本文分享的是自适应构件在Revit正向设计中的一种应用方式.涉及知识点:自适应族.共享参数.报告参数. 图1.自适应构件使用演示GIF,斑马自绘 1.需求来源 在建筑施工图设计中,消防设计是非常 ...

  5. REVIT中一次性导出项目里的族及“项目族管理”操作

    一.Revit中如何将项目里的族一次性导出 如何将一个项目中的族导出? 1.单击应用程序菜单,从下拉列表中选择"另存为"→"库"→"族",如 ...

  6. easyUI 运用窗口和form表单制作导出功能

    这里运用到easyUI的窗口模式和form表单的提交制作一个有条件的导出excel数据统计的功能,主要是知道了怎么运用easyUI的窗口和表单 jsp中: <!-- 导出数据来源条件窗口 --& ...

  7. 建模助手(Revit)【构件二维码功能】将构件装进二维码

    "您好,麻烦出示健康码"这句话仿佛已经刻在了我们的DNA里,凭着绿码在手,走遍天下!!! 不得不说,现在的二维码还是很有普及性,除了上面说的"健康码",生活中的 ...

  8. Revit结构构件之间的扣减问题及解决

    结构模型大家都不陌生了,模型搭建过程中会有很多自动规则,如自动连接;那么大家有没有好奇这些自动规则是什么样的,实现条件又是什么呢? 今天这篇文章就来说说结构构件之间的扣减问题. 一.自动扣剪的条件 在 ...

  9. sqoop导出数据单mysql_sqoop导出hive表数据到mysql

    直接在mysql里从本地文件系统导入数据 mysql>LOAD DATA LOCAL INFILE 'C:\\Users\\asys\\Documents\\Tencent Files\\131 ...

最新文章

  1. 计算机学硕哪些学校好考,什么学校研究生好考,计算机专业研究生哪个学校好考一点...
  2. element表格多列排序_Excel表格在工作中的经典用法,建议收藏!
  3. linux安装tf-gpu注意事项
  4. 11月17日学习内容整理:jquery文档处理,事件细讲,动画
  5. css 中 的作用
  6. boost::sort模块实现spreadsort 反向字符串排序示例
  7. 【每日SQL打卡】​​​​​​​​​​​​​​​DAY 3丨行程和用户【难度困难】
  8. 任务调度(三)——Timer的替代品ScheduledExecutorService简单介绍
  9. 在Java中编写实现_在运行时编写和实现新的Java类文件
  10. 域控下更改服务器密码策略,修改windows-2008-域控服务器密码策略
  11. VB2010(3)整型运算
  12. 搜狗新闻爬取怎么破解反爬机制呀,求指教
  13. 账号密码管理系统html,管理员密码一般是啥
  14. win下装django
  15. win10自动重启另辟蹊径解决方案
  16. 国庆中秋除了发月饼,企业更应该做什么?
  17. 重庆新地标佛罗伦萨小镇将开业;雅高宣布2021年开业新酒店计划;阅文集团出售懒人听书股权​ | 美通企业周刊...
  18. 虚拟机服务器校园网访问设置,配置VMware虚拟机用绕过校园网达到无线上网配置方法...
  19. Joomla远程代码执行漏洞分析小白版(小宇特详解)
  20. 工信部网站备案的备案流程

热门文章

  1. JAVA生成二维码(一)
  2. 关于二叉树重构的思索
  3. 力扣每日一题每天自动邮件提醒
  4. soj 3172 Fisherman (01背包的装满)
  5. 安卓低功耗蓝牙——手机作为外围设备
  6. 手游代理行业,现在还有机会吗?
  7. amp;#9733;《唐琅探案》后记【2】
  8. passwd -l 锁与linux用户属性修改与sbin/nologin区别
  9. [搬运]一百三十四 - TikTok原评论区搬运(机翻)
  10. H5上传图片并使用canvas制作海报