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

4 篇文章 1 订阅

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();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值