revit二次开发之找到与管道连接的连接器名称【比目鱼原创】

=========【更多高级应用请关注公众号】========


===================================


很多时候我们都需要知道管道连接了哪些连接件,以下的代码就能帮助解决这个需求。

PS:无论是查找管道,或者连接件,只需改动几行代码就能实现。


 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 refPipe = sel.PickObject(ObjectType.Element, "pipe");
            Pipe pipe = doc.GetElement(refPipe) as Pipe;
            ConnectorSetIterator csi = pipe.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("管道所连接的连接件名称是:", connected.Owner.Name);
                                }
                            }
                        }
                    }
                }
            }


            ts.Commit();


            return Result.Succeeded;
        }

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值