您的位置:首页 > 其它

RevitAPI:创建不连接任何设备的导线Wire.Create

2016-02-26 16:40 309 查看
Revit 2015暴露了一个方法用来创建导线,那就是:

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: