Revit机电二次开发之如何打断机电管线
来源:互联网 发布:知乎 长期熬夜保健品 编辑:程序博客网 时间:2024/06/08 04:15
本文开发环境为C#,Revit2014
Revit机电二次开发API并没有提供打断管件的方法,只能采用间接的办法实现,思路就是将需要打断的管件就地复制一根,然后将两根管件缩短并放置在合适的位置,同时应当考虑管件与原管路系统的连接问题,以风管Duct为例,C#实现的代码如下:
[TransactionAttribute(TransactionMode.Manual)]public class Test : IExternalCommand{ Autodesk.Revit.ApplicationServices.Application application; Autodesk.Revit.DB.Document document; public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication revit = commandData.Application; application = revit.Application; UIDocument uiDocument = revit.ActiveUIDocument; document = uiDocument.Document; using (Transaction transaction = new Transaction(document, "风管打断")) { transaction.Start(); DuctSelectionFilter ductSelectionFilter=new DuctSelectionFilter(); IList<Duct> ductList=new List<Duct>(); //选取一个风管 Duct duct = PickMEPCurve(uiDocument, ductSelectionFilter, "请选择一个风管") as Duct; XYZ pointOnDuct = PickPointOnMEPCurve(uiDocument, duct as MEPCurve, "请选择一个打断点"); IList<MEPCurve> mepList = SliceMEPCurveIntoTwo(duct as MEPCurve, pointOnDuct, document); transaction.Commit(); } }}//风管选择过滤器class DuctSelectionFilter : ISelectionFilter{ public bool AllowElement(Element element) { if (element is Duct) { return true; } return false; } public bool AllowReference(Reference refer, XYZ point) { return false; }}//选择一个机电管件MEPCurve PickMEPCurve(UIDocument uiDocument,ISelectionFilter selectionFilter,string promptTextWhilePickingElement){ Selection selection = uiDocument.Selection; Reference mepReference = selection.PickObject(ObjectType.Element, selectionFilter, promptTextWhilePickingElement); return uiDocument.Document.GetElement(mepReference) as MEPCurve;}//在管件上选择一个打断点XYZ PickPointOnMEPCurve(UIDocument uiDocument,MEPCurve mep,string promptTextWhilePickingPoint){ Selection selection = uiDocument.Selection; XYZ selectedPoint = selection.PickPoint(ObjectSnapTypes.Nearest, promptTextWhilePickingPoint); LocationCurve locationCurve = mep.Location as LocationCurve; IntersectionResult intersectionResult = locationCurve.Curve.Project(selectedPoint); return intersectionResult.XYZPoint;}//打断管件IList<MEPCurve> SliceMEPCurveIntoTwo(MEPCurve mepCurve, XYZ point, Document document){ IList<MEPCurve> mepCurveList = new List<MEPCurve>(); LocationCurve locationCurve = mepCurve.Location as LocationCurve; XYZ start_point = locationCurve.Curve.GetEndPoint(0); XYZ end_point = locationCurve.Curve.GetEndPoint(1); Curve line1 = Line.CreateBound(start_point, point); Curve line2 = Line.CreateBound(point, end_point); //原地复制原机电管线 MEPCurve newMEPCurve = document.GetElement(ElementTransformUtils.CopyElement(document, mepCurve.Id, new XYZ(0, 0, 0)).ElementAt(0)) as MEPCurve; LocationCurve newLocationCurve = newMEPCurve.Location as LocationCurve; //为复制的机电管线指定基线 newLocationCurve.Curve = line1; //断开原机电管线的连接,建立新机电管线的连接 ConnectorSetIterator connectorSetIterator = mepCurve.ConnectorManager.Connectors.ForwardIterator(); while (connectorSetIterator.MoveNext()) { Connector connector = connectorSetIterator.Current as Connector; if (connector.Origin.IsAlmostEqualTo(start_point)) { ConnectorSet tempConnectorSet = connector.AllRefs; ConnectorSetIterator tempConnectorSetIterator = tempConnectorSet.ForwardIterator(); while (tempConnectorSetIterator.MoveNext()) { Connector tempConnector = tempConnectorSetIterator.Current as Connector; if (tempConnector != null) { if (tempConnector.ConnectorType == ConnectorType.End || tempConnector.ConnectorType == ConnectorType.Curve || tempConnector.ConnectorType == ConnectorType.Physical) { if (tempConnector.Owner.UniqueId != mepCurve.UniqueId) { connector.DisconnectFrom(tempConnector); ConnectorSetIterator newConnectorSetIterator = newMEPCurve.ConnectorManager.Connectors.ForwardIterator(); while (newConnectorSetIterator.MoveNext()) { Connector newConnector = newConnectorSetIterator.Current as Connector; if (newConnector.Origin.IsAlmostEqualTo(start_point)) { newConnector.ConnectTo(tempConnector); } } } } } } } } //缩短原机电管线 locationCurve.Curve = line2; mepCurveList.Add(newMEPCurve); mepCurveList.Add(mepCurve); return mepCurveList;}
由于Revit中Duct、Pipe、CableTray三个机电系统族的基类都是MEPCurve,所以上面的三个方法用在Duct、Pipe和CableTray都是可以,强制转换即可
1 0
- Revit机电二次开发之如何打断机电管线
- 机电一体化
- 机电行业如何进行信息化建设
- 机电方向学习之苦甜心得
- Revit二次开发之如何选取Revit元素【比目鱼原创】
- 如何开始Revit二次开发
- 如何开始Revit二次开发
- Revit二次开发之入门
- 如何查看本机电脑flash的版本
- 实战篇:finereport如何搭建机电行业综合管理平台
- 如何获取本机电脑的AD域名称
- 计算机电子书下载
- 计算机电子书
- 10机电一
- Oracle AutoVue 机电一体化
- 计算机电子书下载
- 上海机电工业学校
- Revit二次开发之“族”操作
- GridView(实现表格显示图标)
- 用Notepad++格式化js代码
- js控制表格静态分页显示
- Openwrt 编译报错:rootfs image is too big解决方法
- 学习android编程之路(5)— Toast使用方法
- Revit机电二次开发之如何打断机电管线
- POI-----POI核心类
- WEB-INF目录与META-INF目录的作用
- PullToRefresh下拉刷新(内附下载地址)
- 获取windows10小图标消失的解决办法
- 华为 OJ 初级 输入一个int型数据,计算出该int型数据在内存中存储时1的个数。
- c,c++库函数、win32库函数、mfc
- C_动态内存分配,malloc/free
- WebView的简单使用