PipingSystem,Connector

PipingSystem,Connector

reylorente1
Collaborator Collaborator
1,088 Views
2 Replies
Message 1 of 3

PipingSystem,Connector

reylorente1
Collaborator
Collaborator

2020-09-14 (3).pngTengo un sistema de tuberia,que contiene 19 tuberias,Desearia obtener los conectores,pero solo me da dos conectores,por que?

I have a pipe system, which contains 19 pipes, I would like to get the connectors, but it only gives me two connectors, why?

Aqui estas mi codigo

Here you are my code

 

public void Get_Connector_PipingSystem(Document doc)
        {
            List<MEPCurve> mEPCurves = new List<MEPCurve>();
            List<Connector> connectors = new List<Connector>();

            foreach (PipingSystem pipingSystem in new FilteredElementCollector(doc).OfClass(typeof(PipingSystem))
                                                                                     .WhereElementIsNotElementType())
            {
                if (pipingSystem.SystemType == PipeSystemType.DomesticColdWater)
                {
                    if (pipingSystem.IsWellConnected == true)
                    {
                        ElementSet elementSet = pipingSystem.PipingNetwork;
                        //string datos = "";
                        //ConnectorSet connectors = null;

                        foreach (Element elem in elementSet)
                        {
                            //FamilyInstance fi = elem as FamilyInstance;
                            //if (fi == null)
                            //{
                            //    continue;
                            //}
                            if (elem is MEPCurve)
                            {
                                //MEPCurve mepCurve = elem as MEPCurve;
                                mEPCurves.Add(elem as MEPCurve);//Add 19 pipes
                                foreach (MEPCurve mepCurve in mEPCurves)
                                {
                                    connectors = GetConnectors(mepCurve);

                                }
                            }
                        }

                        //....
                    }
                }
            }

            TaskDialog.Show("Info", connectors.Count.ToString());
        }

//Input MEPCurve object, e.g. Pipe, Duct, CableTray, Wire
        //Function returns list of connectors from MEPCurve object
        private List<Connector> GetConnectors(MEPCurve mepCurve)
        {
            //1. Get connector set of MEPCurve
            ConnectorSet connectorSet = mepCurve.ConnectorManager.Connectors;
            //2. Initialise empty list of connectors
            List<Connector> connectorList = new List<Connector>();
            //3. Loop through connector set and add to list
            foreach (Connector connector in connectorSet)
            {
                connectorList.Add(connector);
            }
            return connectorList;
        }

 

0 Likes
Accepted solutions (1)
1,089 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

You should step through but the issue seems to be as follows.

 

Your function 'GetConnectors' is outputting a new list of two items for each curve processed i.e. no accumulation due to overwriting list variable with new list. Each curve has two ends the first and the last.

 

Should pass the list as an argument to GetConnectors then add to it and return it. I would pass it by ref and then there is no need to return it after adding to it. By ref is how it would work for reference types such as lists anyway i.e. you can pass the list as an argument and add to it without the need to return it or reassign connectors variable from result of 'GetConnectors' function.

 

Still have to ensure you are not using 'new' keyword for list in 'GetConnectors' function.

0 Likes
Message 3 of 3

reylorente1
Collaborator
Collaborator
I did it, thanks for your suggestion

 

0 Likes