Revit API 楼板开洞
start
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdFloorOpening : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Selection sel = uiDoc.Selection;
Autodesk.Revit.Creation.Application aCreate = cmdData.Application.Application.Create; Transaction ts = new Transaction(doc, "www");
ts.Start();
//楼板
Reference refFloor = sel.PickObject(ObjectType.Element, "floor");
Floor floor = doc.GetElement(refFloor) as Floor;
Face face = FindFloorFace(floor);
CurveArray curves = aCreate.NewCurveArray();
//风管
Reference refDuct = sel.PickObject(ObjectType.Element, "duct");
Duct duct = doc.GetElement(refDuct) as Duct;
Curve curve = FindDuctCurve(duct);
//求交点
XYZ xyz = FindFaceCurve(face, curve);
/*开矩形洞*/
XYZ xyz1 = xyz + new XYZ(1, 1, 0) * 200 / 304.8;
XYZ xyz2 = xyz + new XYZ(1, -1, 0) * 200 / 304.8;
XYZ xyz3 = xyz + new XYZ(-1, -1, 0) * 200 / 304.8;
XYZ xyz4 = xyz + new XYZ(-1, 1, 0) * 200 / 304.8;
Curve c1 = aCreate.NewLine(xyz1, xyz2, true);
Curve c2 = aCreate.NewLine(xyz2, xyz3, true);
Curve c3 = aCreate.NewLine(xyz3, xyz4, true);
Curve c4 = aCreate.NewLine(xyz4, xyz1, true);
curves.Append(c1);
curves.Append(c2);
curves.Append(c3);
curves.Append(c4); /*开圆形洞
double startAngle = 0;
double midAngle = Math.PI;
double endAngle = 2 * Math.PI; XYZ xAxis = XYZ.BasisX;
XYZ yAxis = XYZ.BasisY;
double radius = 180 / 304.8; Arc arc1 = aCreate.NewArc(xyz, radius, startAngle, midAngle, xAxis, yAxis);
Arc arc2 = aCreate.NewArc(xyz, radius, midAngle, endAngle, xAxis, yAxis); curves.Append(arc1);
curves.Append(arc2);*/ doc.Create.NewOpening(floor, curves, true); ts.Commit(); return Result.Succeeded;
}
//求线和面的交点
public XYZ FindFaceCurve(Face face, Curve curve)
{
//求交点
IntersectionResultArray intersectionR = new IntersectionResultArray();//交点集合
SetComparisonResult comparisonR;//Comparison比较
comparisonR = face.Intersect(curve, out intersectionR);
XYZ intersectionResult = null;//交点坐标
if (SetComparisonResult.Disjoint != comparisonR)//Disjoint不交
{
if (!intersectionR.IsEmpty)
{
intersectionResult = intersectionR.get_Item(0).XYZPoint;
}
}
return intersectionResult;
}
//找到风管对应的曲线
public Curve FindDuctCurve(Duct duct)
{
//得到风管曲线
IList<XYZ> list = new List<XYZ>();
ConnectorSetIterator csi = duct.ConnectorManager.Connectors.ForwardIterator();
while (csi.MoveNext())
{
Connector conn = csi.Current as Connector;
list.Add(conn.Origin);
}
Curve curve = Line.get_Bound(list.ElementAt(0), list.ElementAt(1)) as Curve;
curve.MakeUnbound();
return curve;
}
//找到楼板的面
public Face FindFloorFace(Floor floor)
{
Face normalFace = null;
//
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
//
GeometryElement e = floor.get_Geometry(opt);
/*下版改进
IEnumerator<GeometryObject> enm = e.GetEnumerator();
while (enm.MoveNext())
{
Solid solid = enm.Current as Solid;
}*/
foreach (GeometryObject obj in e.Objects)//待改2013
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
{
foreach (Face face in solid.Faces)
{
PlanarFace pf = face as PlanarFace;
if (pf != null)
{
if (pf.Normal.AngleTo(new XYZ(0, 0, -1)) < 0.01)//数值在0到PI之间
{
normalFace = face;
}
}
}
}
}
return normalFace;
}
}
url:http://greatverve.cnblogs.com/p/revit-api-FloorOpening.html
Revit API 楼板开洞的更多相关文章
- 【Revit API】梁构件支座检查算法
一.前言 应该是第二次写关于Revit API的博文了.虽然在BIM企业中工作,从事桌面BIM软件开发,但是我是不怎么喜欢写Revit API相关的代码.平时更多的是在写界面展示,架构 ...
- Revit API 判断一个构件在某个视图中的可见性
查看 Revit API.发现有Element::IsHidden这个方法.通过UI创建一个element,注意要使得这个element在某些视图可见,但是在另一些视图不可见.运行下面的方法,你会发现 ...
- Revit API 操作共享参数和项目参数
1.获取共享参数 private string GetSharInfo(Autodesk.Revit.ApplicationServices.Application revitApp) { Strin ...
- Revit API射线法读取空间中相交的元素
Revit API提供根据射线来寻找经过的元素.方法是固定模式,没什么好说.关键代码:doc.FindReferencesWithContextByDirection(ptStart, (ptEnd ...
- Revit API 加载族并生成实例图元
在Revit API中加载族可以使用Doc.LoadFamily方法,传入要加载的族文件路径名,但是这种方式有一种缺点,就是如果族文件在当前工程中没有加载的话则返回成功,如果已经加载过,则返回失败,也 ...
- Revit API根据链接文件开洞
开洞信息数据: ]); ; ; ; ; ...
- Revit API遍历全部风管,找到与风管相关的墙开洞
涉及向量计算,求相交等相关技术. ) { foreach (Face face in solid.Faces) ...
- Revit API 获取某墙上洞口的尺寸和位置
[Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd2012 ...
- 【Revit API】调用Revit内部命令PostableCommand
Revit内置了一些命令,直接调用Revit操作方式. 可以去API文档查询PostableCommand枚举,还是很多的. 话不多说,直接上代码 var commandId = RevitComma ...
随机推荐
- MySQL-->基础-->001-->MySQL基本操作
一.MySQL安装 卸载mysql 第一步 sudo apt-get autoremove --purge mysql-server-5.0 sudo apt-get remove mysql-ser ...
- oracle备忘
一.explain plan a)explain plan for select ... select * from table(dbms_xplan.display()); function dis ...
- 浏览器css bug及bug解决方法
Bugs及解决方案列表(以下实例默认运行环境都为Standard mode): 如何在IE6及更早浏览器中定义小高度的容器? 方法: #test{overflow:hidden;height:1px; ...
- Linux2
linux开源软件 :apache软件 nginx支持更高的并发访问 MySQL PHP samba mongoDB python 应用领域: 一:服务器 二:嵌入式
- boa移植
1.交叉编译 2.复制文件 配置文件boa.conf 移动到/etc/boa/ 目录下 可执行文件boa移动到/usr/sbin/目录下 3.修改配置文件 4.将Linux系统上/etc/mime.t ...
- Hibernate之创建命名策略
在开发软件时,通常会要求每个开发人员遵守共同的命名策略.例如,数据库的表名及字段名的所有字符都要大写,表名以“S”结尾.对于Customer类,对应的数据库表名为CUSTOMERS.为了在映射文件中遵 ...
- 多线程JAVA篇(一)
解析AsyncTask源码之前,首先讲述与之相关的Java线程知识: 知识点清单 1.Thread类 2.Runnable接口 3.Callable接口 4.synchronized关键字 5.vol ...
- web兼容性测试
1.前端的兼容性问题 a. 客户端操作系统 -pc电脑 -windows -mac os -Linux -平板 -手机 -智能终端 -响应式布局 借助于css3 b.客户端浏览器 IE firefo ...
- SQL Server高级性能调优策略
论坛里经常有人问“我的数据库很慢,有什么办法提高速度呢?”.这是个古老的话题,又是常见的问题,也是DBA们最想解决的问题之一.我想就SQLServer调优大家一起论一论,如果可以的话尽量发表自己观点, ...
- 第二章-如何使用github建立一个HelloWorld项目,git的add/commit/push/pull/fetch/clone等基本命令用法。--答题人:杨宇杰
1.配置Git 首先在本地创建ssh 秘钥:在git bash输入: $ ssh-keygen -t rsa -C "your_email@youremail.com" eg:$ ...