RevitAPI:创建不连接任何设备的导线Wire.Create
2016-02-26 16:40
309 查看
Revit 2015暴露了一个方法用来创建导线,那就是:
注意这里的最后两个参数,是Connector。意味着要创建导线必须先有两个Connector,根据以往RevitAPI的规则,可能认为Connector如果是空的话,Revit就会抛出ArgumentNullException,表面上看可能无法创建。
但是查看该方法关于最后两个参数的文档:
startConnectorTo
The connector to which the wire start point connects. If nullNothingnullptra null reference (Nothing in Visual Basic), the start point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices
as the start point.
endConnectorTo
The connector to which the wire end point connects. If nullNothingnullptra null reference (Nothing in Visual Basic), the end point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices as
the end point.
说明最后两个Connector是可以接受空值的,如果是空值,那么该导线就不和任何设备连接。
于是示例代码如下:
public class Wire { static Wire Create(Document document, ElementId wireTypeId, ElementId viewId, WiringType wiringType, IList<XYZ> vertexPoints, Connector startConnectorTo, Connector endConnectorTo); }
注意这里的最后两个参数,是Connector。意味着要创建导线必须先有两个Connector,根据以往RevitAPI的规则,可能认为Connector如果是空的话,Revit就会抛出ArgumentNullException,表面上看可能无法创建。
但是查看该方法关于最后两个参数的文档:
startConnectorTo
The connector to which the wire start point connects. If nullNothingnullptra null reference (Nothing in Visual Basic), the start point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices
as the start point.
endConnectorTo
The connector to which the wire end point connects. If nullNothingnullptra null reference (Nothing in Visual Basic), the end point connects to no existing connector. If set with a connector, the connector's origin will be added to the wire's vertices as
the end point.
说明最后两个Connector是可以接受空值的,如果是空值,那么该导线就不和任何设备连接。
于是示例代码如下:
Transaction transaction = new Transaction(doc, "create independent wire"); transaction.Start(); try { var viewId = doc.ActiveView.Id; WireType wireType = new FilteredElementCollector(doc) .OfClass(typeof(WireType)).Cast<WireType>() .FirstOrDefault(/*el => el.Name == "VV"*/); if (wireType != null) { var points = new List<XYZ>() { new XYZ(), new XYZ(10, 0, 0), new XYZ(10, 10, 0) }; var wire = Wire.Create(doc, wireType.Id, viewId, WiringType.Chamfer, points, null, null); } else { TaskDialog.Show("ERROR", "WireType not found"); } transaction.Commit(); } catch (Exception) { transaction.RollBack(); }
相关文章推荐
- Link/Cut Tree
- Simple Game
- SSM-如何验证事务是否生效
- mybaits之动态sql
- scala note
- 单链表的创建/测长/打印
- Material Design Theme
- 获取私有变量名称
- linux vi 删除多行的方法
- 【BZOJ2741】FOTILE模拟赛 L
- ios 资源很全面转载以后方便看
- docker 升级版本
- 【hdu5015】233 Matrix——矩阵快速幂
- oracle中使用物化视图实现表的同步
- Mac OS X 下开启PHP
- Adroid: getExternalStorageDirectory 不一定是你想要的外部存储SdCard
- Spring Aop自定义注解实现日志管理
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- 从数组谈队列
- YII url美化管理