vanlion
vanlion

Reputation: 111

How to add Results for loop to List

I working with a revit code to collect CurveLoops and create a loft geometry.

Creating the CurveLoops is working fine with a for loop(creates lines from points). But it creates two separate CurveLoops.

I've tried to add the for loop result to a new list(profile3). But it returns two list with one CurveLoop in it. In my case it should be two CurveLoops in one list(profile3)

CurveLoop profileLoop = new CurveLoop();

List<CurveLoop> profile3 = new List<CurveLoop>();

SolidOptions options = new SolidOptions(ElementId.InvalidElementId,
ElementId.InvalidElementId);

for (int i = 0; i < p.Count - 1; ++i)
{
    // Create lines and convert points to mm
    Line line = Line.CreateBound(p[i] / 304.8, p[i + 1] / 304.8);
    //Append points to CurveLoop
    profileLoop.Append(line);
}

//Here I want to add both created CurveLoops to list
profile3.Add(profileLoop);

//Create Loft
Solid loft = GeometryCreationUtilities.CreateLoftGeometry(profile3
    , options);

Loft can't be created because it only has one curveloop in the list and it needs both created from the for loop

First CurveLoop and Second CurveLoop that should be in one list First CurveLoop and Second CurveLoop that should be connected

Upvotes: 1

Views: 469

Answers (2)

Thierry Prost
Thierry Prost

Reputation: 1025

Problem

What you are doing here is passing the same object multiple times into a list and then wonder how come all the objects in the list are the same.

Solution

You might want to look at the concept of passing by reference and the difference between reference types and value types.

Upvotes: 0

Leonardo Garcia
Leonardo Garcia

Reputation: 11

It looks like you need to add the same CurveLoop to the list twice. So you will end up with one list with two matching elements.

I would suggest doing a second profile3.Add(profileLoop);

You aren't really creating two different CurveLoops in that for iterator, just one. So you would need to add it twice to the list in order for your result to work.

Upvotes: 1

Related Questions