C# output with unwanted sublist

Hi Everyone,
I’m trying to create a plugin to cutting the building model by named CPlanes using C# Visual Studio. I can filter and get the name of CPlanes as expected. Once i added the code to output Planes, the output contains more items than i need. I just begin to learn C#. Please advise how to achieve the result. Thanks.
Get CPlanes.3dm (55.8 KB)

Code for Get Names of CPlanes

            pManager.AddBooleanParameter("Update", "Update", "Update CPlanes info", GH_ParamAccess.item);
            pManager.AddTextParameter("Name", "N", "Cplanes Names", GH_ParamAccess.list);
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool iUpdate = false;
            DA.GetData("Update", ref iUpdate);

            List<Plane> oPlanes = new List<Plane>();
            List<string> cPlaneName = new List<string>();
            List<string> oName = new List<string>();
            var doc = RhinoDoc.ActiveDoc;
            var cPlanes = doc.NamedConstructionPlanes;
            if (iUpdate)
            {
                for (int i = 0; i < cPlanes.Count; i++)
                {
                    cPlaneName.Add(cPlanes[i].Name);
                }
                foreach (string mylist in cPlaneName.Where(a => a.Contains("mPD")))
                    oName.Add(mylist);
                    DA.SetDataList("Name", oName);
            }
        }

Code for Get Planes

        {
            bool iUpdate = false;
            DA.GetData("Update", ref iUpdate);

            List<Plane> oPlanes = new List<Plane>();
            List<string> cPlaneName = new List<string>();

            var doc = RhinoDoc.ActiveDoc;
            var cPlanes = doc.NamedConstructionPlanes;

            if (iUpdate)
            {
                for (int i = 0; i < cPlanes.Count; i++)
                {
                    cPlaneName.Add(cPlanes[i].Name);
                }
                foreach (string mylist in cPlaneName.Where(a => a.Contains("mPD")))
                {
                    int CPindex = RhinoDoc.ActiveDoc.NamedConstructionPlanes.Find(mylist);
                    Plane getPlanes = RhinoDoc.ActiveDoc.NamedConstructionPlanes[CPindex].Plane;
                    oPlanes.Add(getPlanes);
                    DA.SetDataList("Plane", oPlanes);
                }
            }
        }

Call all SetData methods outside your for each loop . Give that a try.

It works. Thanks a lot. Great help. I can move on to next step.
Haha…i’m so stupid. Searching on web for few days.

No worries, but logically it doesn’t make sense to call that method inside a loop. It should only be used outside loops. Because then you would send data as output at each loop iteration.

Also you can do what you are doing within a C# component, if your code will not be that long, under 1000 lines of code.

Nothing to add, I just edited the OP to use triple backticks for proper code markup. I specified C# for code like so:

```csharp
some code here
```