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 ...
随机推荐
- 存在网路的情况下重命名SDE中数据图层错误(The orphan junction feature class cannot be renamed)
运行环境为ArcGIS9.3,VS2008. 问题描述:数据通过SDE存储在Oracle10g数据库中,数据集中存在几何网络,在存在网络的情况下通过程序对其中的数据图层进行重命名,弹出"Th ...
- android studio 代理配置
android studio 代理设置,只支持http代理,不能用ss服务 中间加一层http转换 1远端ss 2client ss 端口 A 3client privoxy服服 代理ss A端口 到 ...
- hadoop中master免登录slave
hadoop集群免登录配置 在主机master上执行如下: 1. $cd ~/.ssh(如果没有此目录,可以手动创建) 2. $ssh-keygen -t rsa ----------------- ...
- BigDecimal类的加减乘除
Java在java.math包中提供的API类BigDecimal,用来对超过16位有效位的数进行精确的运算. 双精度浮点型变量double可以处理16位有效数,但是在实际应用中,需要对更大或者更小的 ...
- $watch监听数据变化和run方法
angular中$watch方法可以监听数据的变化. $scope.$watch('phone',function(){ $scope.phone.fre = $scope.phone.num> ...
- sed初学
1.连接多个sed命令,使用;号 2.批量修改文本中匹配到相应字符串的行 例如,将文本中log_server_port = "12345" 的12345修改成变量中存储的值 sed ...
- textarea 在不同浏览器高宽不一致的兼容性问题
在html,很多同学喜欢使用rows.cols,来设置textarea的高宽,却发现,在火狐跟其他浏览器,好像高宽却不一致! 因为这是火狐的一个bug, https://bugzilla.mozill ...
- Linux下安装软件的一般步骤
目录 一.解析Linux应用软件安装包 二.了解包里的内容 三.搞定使用tar打包的应用软件 四.搞定使用rpm打包的应用软件 五.搞定使用deb打包的应用程序 一.解析Linux应用软件安装包(回目 ...
- FreeBSD_11-系统管理——{Part_3-网络}
一.Network Servers DNS unbound/local_unbound # /etc/rc.conf local_unbound_enable="YES" # 测试 ...
- shell脚本学习
1.注释 如果使用bash,则在脚本文件头注释:#/bin/bash2.将脚本文件加上可读与执行权限,就可以使用./shell.sh来执行,也可以使用sh shell.sh的方式来直接执行,sh是ba ...