以前就已经对创建房间有过了解,只是点到为止没有进一步的深究下去,今天有点时间就整理一下思路,留着以后备用。其实创建完房间后,可以算房间面积,空间体积什么的,也可以获得房间的边界线去做一些工作,比如生成楼板,墙踢脚线,墙饰条等等,其实原理都一样就是利用房间的闭合曲线!

首先来一个批量创建房间的代码,这里就只写步骤了,不拷贝整个工程了

UIApplication uiApp = commandData.Application;

UIDocument uidoc = uiApp.ActiveUIDocument;

Document doc = uidoc.Document;

ViewPlan view = uidoc.ActiveView as ViewPlan;

Transaction ts = new Transaction(doc, "BIM");

ts.Start();

Level level = uidoc.ActiveView.GenLevel;

PlanTopology pt = doc.get_PlanTopology(level);

foreach (PlanCircuit pc in pt.Circuits)

{

if (!pc.IsRoomLocated)

{

Room newRoom = doc.Create.NewRoom(null, pc);

LinkElementId elemid = new LinkElementId(newRoom.Id);

Location location = newRoom.Location;

LocationPoint locationPoint = location as LocationPoint;

XYZ point3d = locationPoint.Point;

UV point2d = new UV(point3d.X, point3d.Y);

RoomTag roomTag = doc.Create.NewRoomTag(elemid, point2d, view.Id);

if (family != null)

{

try

{

//这里的symbol其实是自定义的一个房间标记族,可以自行导入,这里就不再介绍了

FamilySymbol symbol = family.Document.GetElement(family.GetFamilySymbolIds().First()) as FamilySymbol;

if (symbol != null)

{

roomTag.ChangeTypeId(symbol.Id);

}

}

catch { }

}

}

}

ts.Commit();

以上代码就是批量生成房间的代码段,接下来就是获得房间边界生成楼板,不过在此之前我们先看看每个房间边界的样子,我们可以根据Room.GetBoundarySegments()方法来获得 IList<>集合,根据这个集合去遍历所有的房间边界,在此之前我们还需要一个SpatialElementBoundaryOptions选项,它给我们提供了SpatialElementBoundaryLocation枚举类型,公有四个,分别是,Center,CoreBoundary,CoreCenter,finish,那么分别是什么意思呢,查阅一下RevitAPI帮助文档后得知:

1.Center,这里可以理解为墙的中心线

2.CoreBoundary,这里可以理解为墙的核心层边界线

3.CoreCenter,这里可以理解为墙的核心层中心线

4,.Finish.这里可以理解为墙的面层

上述翻译有可能不太准确,希望读者自行实验判断吧,接下来我们实测一下这四个选项,我的思路是根据房间的边界线生成详图线用以观察四个选项的区别,为了明显起见我想自定义一个线样式,宽度为1个单位,颜色为红色,主要代码如下:

生成线样式

using (Transaction ts = new Transaction(doc, "LineStyle"))

{

ts.Start();

Category lineCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

Category newCategory = doc.Settings.Categories.NewSubcategory(lineCategory, "房间边界线");

Color newColor = new Color(255, 0, 0);

newCategory.LineColor = newColor;

newCategory.SetLineWeight(1, GraphicsStyleType.Projection);

ts.Commit();

}

生成之后的系统线样式下:


好了 那么接下来我们就可以过滤房间边界来看一看它们的样子:核心代码,记得开启事务

//这里拾取一个房间,为了简便没有加过滤器限制

Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "");

Room room = doc.GetElement(refer) as Room;

SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;

//声明的Curve集合是为创建楼板而服务的

CurveArray array = new CurveArray();

IList(IList(BoundarySegment)) loops = room.GetBoundarySegments(opt);

foreach (IList(BoundarySegment) loop in loops)

{

foreach (BoundarySegment seg in loop)

{

Curve curve = seg.GetCurve();

//创建详图线,设置它的线样式类型为我们刚才创建的

DetailCurve dc = doc.Create.NewDetailCurve(uidoc.ActiveView, curve);

if (BackLineStyle(doc) != null)

{

SetLineStyle(BackLineStyle(doc), dc);

}

array.Append(dc.GeometryCurve);

}

}

//两个相关的方法

//搜索目标线样式

private Category BackLineStyle(Document doc)

{

Category lineCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

CategoryNameMap map = lineCategory.SubCategories;

foreach (Category g in map)

{

if (g.Name == "房间边界线")

{

return g;

}

}

return null;

}

//设置线样式

private void SetLineStyle(Category cate, DetailCurve line)

{

ElementId Id = new ElementId(cate.Id.IntegerValue + 1);

foreach (Parameter p in line.Parameters)

{

if (p.Definition.Name == "线样式")

{

p.Set(Id);

break;

}

}

}

上述代买我们用的是Center选项,让我们来看看效果:


红色是房价你的边界线的路径,可以看得出与墙中心线重合,我使用的墙结构信息如下:


改变Center选项为Finish后,我们再看看效果:


其他两个选项,读者自行分析吧,这里就不再介绍了:

接上述代码获得房间边界,我们可以创建楼板,以下为核心代码:

//创建楼板,类型默认 标高默认

private void CreateFloor(Document doc,CurveArray array)

{

FloorType floorType= new FilteredElementCollector(doc).OfClass(typeof(FloorType)).FirstOrDefault() as FloorType;

Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OrderBy(o => (o as Level).ProjectElevation).First() as Level;

Floor floor = doc.Create.NewFloor(array,floorType,level,false,XYZ.BasisZ);

}

生成楼板(其实根据闭合曲线能创建很多东西,也可以用其做族的放样,生成散水,踢脚线等,有时间我会写一个创建族的基本流程)之后的局部三维视图如下:

/本项目工程全部代码:

using Autodesk.Revit.UI;

using Autodesk.Revit.DB;

using Autodesk.Revit.Attributes;

using Autodesk.Revit.UI.Selection;

using Autodesk.Revit.DB.Plumbing;

using Autodesk.Revit.DB.Mechanical;

using System.Xml;

using Autodesk.Revit.UI.Events;

using System.Windows.Forms;

using Autodesk.Revit.DB.Events;

using Autodesk.Revit.DB.Architecture;

namespace HelloWorld

{

[Transaction(TransactionMode.Manual)]

[Regeneration(RegenerationOption.Manual)]

public class Test : IExternalCommand

{

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)

{

UIApplication uiApp = commandData.Application;

UIDocument uidoc = uiApp.ActiveUIDocument;

Document doc = uidoc.Document;

if (IsExistLineStyle(doc, "房间边界线"))

{

}

else

{

生成线样式

using (Transaction ts = new Transaction(doc, "LineStyle"))

{

ts.Start();

Category lineCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

Category newCategory = doc.Settings.Categories.NewSubcategory(lineCategory, "房间边界线");

Color newColor = new Color(255, 0, 0);

newCategory.LineColor = newColor;

newCategory.SetLineWeight(1, GraphicsStyleType.Projection);

ts.Commit();

}

}

Transaction ts2 = new Transaction(doc, "BIM");

ts2.Start();

Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "");

Room room = doc.GetElement(refer) as Room;

SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

opt.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish;

CurveArray array = new CurveArray();

IList(IList(BoundarySegment)) loops = room.GetBoundarySegments(opt);

foreach (IList(BoundarySegment) loop in loops)

{

foreach (BoundarySegment seg in loop)

{

Curve curve = seg.GetCurve();

DetailCurve dc = doc.Create.NewDetailCurve(uidoc.ActiveView, curve);

if (BackLineStyle(doc) != null)

{

SetLineStyle(BackLineStyle(doc), dc);

}

array.Append(dc.GeometryCurve);

}

break;

}

CreateFloor(doc, array);

ts2.Commit();

return Result.Succeeded;

}

//设置线样式

private void SetLineStyle(Category cate, DetailCurve line)

{

ElementId Id = new ElementId(cate.Id.IntegerValue + 1);

foreach (Parameter p in line.Parameters)

{

if (p.Definition.Name == "线样式")

{

p.Set(Id);

break;

}

}

}

//判断线样式是否存在

private bool IsExistLineStyle(Document doc, string Name)

{

Category IsCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

CategoryNameMap map = IsCategory.SubCategories;

foreach (Category g in map)

{

if (g.Name == Name)

{

return true;

}

}

return false;

}

//搜索目标线样式

private Category BackLineStyle(Document doc)

{

Category lineCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

CategoryNameMap map = lineCategory.SubCategories;

foreach (Category g in map)

{

if (g.Name == "房间边界线")

{

return g;

}

}

return null;

}

//创建楼板,类型默认 标高默认

private void CreateFloor(Document doc,CurveArray array)

{

FloorType floorType= new FilteredElementCollector(doc).OfClass(typeof(FloorType)).FirstOrDefault() as FloorType;

Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).OrderBy(o => (o as Level).ProjectElevation).First() as Level;

Floor floor = doc.Create.NewFloor(array,floorType,level,false,XYZ.BasisZ);

}

}

}

Revit二次开发之创建房间,根据房间边界创建楼板等相关推荐

  1. 第十三届Revit二次开发实战训练课程22年3月21在武汉举办

    关于举办第十三届Revit开发实战训练课程的通知 各相关单位: 为贯彻落实住建部<2016-2020年建筑业信息化发展纲要>,提升国内建筑行业BIM科研和课题创新能力,强化企业和高校在各个 ...

  2. Revit 二次开发实例分享

                                                                 叶雄进 Joe Ye Autodesk 2010/9/1     Autode ...

  3. Revit二次开发 - C#程序员的佳好选择

    虽然Revit的使用者和开发目前在中国都很少,但是这是个趋势. 未来Revit会在许多方面取代Autocad 做CAD二次开发的,在中国也很吃香. 但是使用C++难倒了许多人. 而Revit二次开发可 ...

  4. Revit二次开发_1.过滤器笔记篇

    Revit二次开发_1.过滤器笔记篇 前言 对象分类 过滤方法 前言 最近在用过滤器功能,先按照教程做了筛选墙,再自己做了筛选常规模型的功能,发现有点不一样,问题在于筛选这些Elements的时候没弄 ...

  5. revit二次开发之教学视频

    一.背景 刚入门revit二次开发的小伙伴,很多是零基础的工程人员,为了解决这个问题,博主做了revit二次开发的一系列教学视频(包括C#基础与revit二次开发两个模块),来帮助大家更好的入门. 二 ...

  6. Revit二次开发——引用dynamo中的几何库

    前沿 dynamo的几何库其实是非常强大的,如果自己靠着RevitAPI去写还是非常费劲的.所以想引用dynamo的几何库来做一些工作.主要参考的就是这篇文章.Revit二次开发--不开启Dynamo ...

  7. revit二次开发之程序调试

    欢迎加入BIM行业开发交流1群 群号:711844216(满),二群群号:1016453207 需要Revit二次开发全流程教学 的朋友可以联系我qq:1056295111 一.背景 小伙伴们在rev ...

  8. revit二次开发之多线程的正确使用

    欢迎加入BIM行业开发交流1群 群号:711844216(满),二群群号:1016453207 一.背景 小伙伴们为了加快revit程序运行速度, 可能会考虑使用多线程,但是我们必须首先搞清楚一个问题 ...

  9. Revit二次开发入门秘籍 01如何入门

    关于入门 我想在开始学习之前大家应该更需要知道如何入门,对比一下我们在学校的学习,我们需要书.老师-书上呢,是有所有的知识点,有重要的,有不重要的,而老师呢,会知道哪些是重点,也就是我们考试要考的,教 ...

最新文章

  1. 手把手教你用python抢票回家过年 !(附代码)
  2. Vue+Openlayers显示TileWMS时不显示默认控件放大缩小旋转等组件
  3. redhat下安装mysql 5.6.20,解压zip包,查看已经安装过的mysql,卸载rpm安装包,安装mysql服务器端和客户端,修改mysql用户名,登陆mysql,启动关闭mysql
  4. OSGI嵌入jetty应用服务器
  5. 最近很火的MySQL:抛开复杂的架构设计,MySQL优化思想基本都在这
  6. Log4net日志发布到服务器上日志无法写入
  7. java excel api 下载文件_Java-Excel Java操作Excel POI(Jakarta POI API) - 下载 - 搜珍网
  8. SQL操作结果集-并集,差集,交集,结果集排序
  9. Source Insight 4.0黑色仿IDEA主题
  10. matlab电磁场 有限元,电磁场有限元Matlab解法.pdf
  11. verilog 笔试题
  12. Vue 中常见的面试题/知识点整理
  13. 微信引流推广:美拍视频简单的引流方法分享
  14. Peer to Peer ( P2P ) 综述
  15. 计算机弹奏怎么录视频教程,怎么录制视频教程?简单、快捷的方法尝试
  16. 压缩机振动探头本特利330904-06-14-05-02-00
  17. 外贸企业邮箱哪个好用?各大公司用的企业邮箱哪家稳定?
  18. 奇瑞新能源小蚂蚁,一款实用好看的居家小车
  19. 计算圆和正方形的面积和周长
  20. 无法访问J盘提示此卷不包含可识别的文件系统的数据找回方法

热门文章

  1. spring mvc 拦截器拦截jsp页面
  2. zabbix监控vSphere
  3. jquery获取图片并压缩上传
  4. 如何使用excel计算工龄
  5. 【机器学习|数学基础】Mathematics for Machine Learning系列之矩阵理论(24):常数项级数的审敛法(补充知识)
  6. 京东官宣涨两个月工资;美团优选取消 996, 开启双休!
  7. python ln()怎么实现_Python math库 ln(x)运算的实现及原理
  8. 计算机信息系统应急演练预案,网络信息系统应急预案
  9. 爱奇艺PC Web NodeJS中间层实践
  10. 做自媒体工具和软件有哪些?整理8类工具分享给大家!