Revit MEP API找到连接器连接的连接器

通过conn.AllRefs;可以找到与之连接的连接器。
// 连接器连接的连接器
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public  class cmdConnected : IExternalCommand
{
     public Result Execute(ExternalCommandData commandData,  ref  string messages, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Selection sel = app.ActiveUIDocument.Selection;

        Transaction ts =  new Transaction(doc,  " revit ");
        ts.Start();

        Reference refDuct = sel.PickObject(ObjectType.Element,  " duct ");
        Duct duct = doc.GetElement(refDuct)  as Duct;
        ConnectorSetIterator csi = duct.ConnectorManager.Connectors.ForwardIterator();
         while (csi.MoveNext())
        {
            Connector conn = csi.Current  as Connector;
             if (conn.IsConnected ==  true) // 是否有连接
            {
                ConnectorSet connectorSet = conn.AllRefs; // 找到所有连接器连接的连接器
                ConnectorSetIterator csiChild = connectorSet.ForwardIterator();
                 while (csiChild.MoveNext())
                {
                    Connector connected = csiChild.Current  as Connector;
                     if ( null != connected && connected.Owner.UniqueId != conn.Owner.UniqueId)
                    {
                         //  look for physical connections 
                         if (connected.ConnectorType == ConnectorType.End ||
                            connected.ConnectorType == ConnectorType.Curve ||
                            connected.ConnectorType == ConnectorType.Physical)
                        {
                             // 判断是不是管件
                             if (connected.Owner  is FamilyInstance)
                            {
                                TaskDialog.Show( " fitting ", connected.Owner.Name);
                            }
                        }
                    }
                }
            }
        }

        ts.Commit();

         return Result.Succeeded;
    }
}
url: http://greatverve.cnblogs.com/p/revit-mep-api-AllRefs.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值