天天看點

revit二次開發之找到與管道連接配接的連接配接器名稱【比目魚原創】

=========【更多進階應用請關注公衆号】========

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;

        }