For loop to create CurveLoop Loft

For loop to create CurveLoop Loft

vanlion
Advocate Advocate
4,476 Views
16 Replies
Message 1 of 17

For loop to create CurveLoop Loft

vanlion
Advocate
Advocate

Hi,

 

I'm trying to create a loft with CreateLoftGeometry. It creates two CurveLoops from points perfectly tested with creation of model lines (see image). But how can I add both CurveLoops to the "profile3" list, so you can use it for CreateLoftGeometry? With my code for now it adds only the first CurveLoop to the list, but I need both.

Capture.PNG

 

 

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);

 

 

0 Likes
Accepted solutions (1)
4,477 Views
16 Replies
Replies (16)
Message 2 of 17

BardiaJahan
Advocate
Advocate

In your snippet you are adding all the lines to one curveloop (profileLoop) but you have to break the for loop somewhere (when the first curveLoop is created), add the curveloop to profile3, then create a different curveloop with the remaining lines in it and add it to profile3. Let's change your snippet to:

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)
            {
                // CurveLoop created with half of the points is added to profile3
// and we start a new curveLoop if (i > p.Count/2) { profile3.Add(profileLoop); profileLoop = new CurveLoop(); } // 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);

Note: it seems you are taking care of the loops being closed by having duplicates of the start points. Otherwise you have to be careful about that too.

Message 3 of 17

vanlion
Advocate
Advocate

Hi,

 

Thanks for helping. I tested your solution by adding a taksdialog to count the CurveLoops that should be two.

 

In the GIF image below you can see what's happening. It counts 4 and in the back ground to make the proces visible i create the model curves. So you can see it makes the first one and after that the second one

 

Loop.gif

0 Likes
Message 4 of 17

BardiaJahan
Advocate
Advocate

Could you share your code so I can see where you added the taskdialog. I also like to know what the code does after selecting the dwg - to retrieve the points?

0 Likes
Message 5 of 17

FAIR59
Advisor
Advisor

By using the  GeometryCreationUtilities, you create a Solid not in a document but in memory.

see http://www.revitapidocs.com/2016/e829700d-48ff-0914-b288-5ceb93d8ee86.htm

 

 

To create a solid ( ==  Form ) in a document use 

Form loft =  doc.FamilyCreate.NewLoftForm(true,refarrarr);

workflow:

  • create the curveloops as ModelCurves in document
  • create LoftForm using the references from the ModelCurves. 
Message 6 of 17

vanlion
Advocate
Advocate

Hi Fair59,

 

Thanks for helping. Yes i know it is a memory geometry my next step was to make a Directshape of the created loft.

 

But i also will take a look at your solution if mine doesn't work. Good alternative!

0 Likes
Message 7 of 17

BardiaJahan
Advocate
Advocate

I made a huge mistake, hahaha .... with that if statement, for every i>p.Count , a new Curveloop is created which is absolutely wrong. But if you change it to the following, I believe the result would be closer to what you expect:

 

for (int i = 0; i < p.Count - 1; ++i)
            {
                // CurveLoop created with half of the points is added to profile3
                // and we start a new curveLoop
                if (i == (p.Count / 2) -1)
                {
                    profile3.Add(profileLoop);
                    profileLoop = new CurveLoop();
                }
                // 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);
            }
Message 8 of 17

vanlion
Advocate
Advocate

Hi,

 

Thanks for your answer but that's not wat i'm looking for. Maybe with the explanation below it's maybe clearer i hope. So i use two times a method to make the script not to long. Becaus of the use of methods you get a CurveLoop from pointlist 1 and a CurveLoop from pointlist 2. I need to add both results to a new list so you can use it to create a Loft. I tried something with a counter so you can get first result method and second result method. But the last step is combine the results in a new list. So you have two Curveloops in one list.

 

Thanks

 

counter++
if (counter == 1) { for (int i = 0; i < p.Count - 1; ++i) { Line line = Line.CreateBound(p[i] / 304.8, p[i + 1] / 304.8); //Append points to CurveLoop profileArr.Append(line); profileLoop.Append(line); } profile3.Add(profileLoop); }

 

Annotation 2019-05-07 151804.png

0 Likes
Message 9 of 17

BardiaJahan
Advocate
Advocate

I am a little confused!! You are not adding profileArr to profile3 though .... 

0 Likes
Message 10 of 17

vanlion
Advocate
Advocate

Sorry that doesn't need to be there. It was from a test to create a floor from the lines

 

But i can't edit my post, so i can't remove it 😉

0 Likes
Message 11 of 17

BardiaJahan
Advocate
Advocate

and how about the counter? the whole process happens when counter equals 1

0 Likes
Message 12 of 17

vanlion
Advocate
Advocate

With the counter i get control on how many times a method is called.

 

In call 1 it creates the curveloop above and call 2 the curveloop below. But i need to get call 1 and call 2 together in one list.

 

0 Likes
Message 13 of 17

BardiaJahan
Advocate
Advocate

You are adding both to profile3, right? 

0 Likes
Message 14 of 17

vanlion
Advocate
Advocate

Yes, that's need to be the final result so you can use the curveloop from call 1 and call 2 that are added to profile 3 to make the loft

0 Likes
Message 15 of 17

BardiaJahan
Advocate
Advocate
Accepted solution

So just a recap, you are calling a method (two times) and in that method a curveloop is created which is supposed to be added to your curveloop list in order to eventually create the loft geometry. You list of curveloops (profile3) cannot be created in this method though. You have two options:

1- pass profile3 as a reference argument and have the curveloop added to it. something like this:

public void CreateCurveloop( List<XYZ> p, ref List<CurveLoop> profile3)
{
     //everything that needs to be done
     profile3.Add(profileLoop);
}

2- return the curveloop and in the scope where you call method CreateCurveLoop, create profile3 and add the return curveloop to it. Something like this:

public CurveLoop CreateCurveloop( List<XYZ> p)
{
     //...everything that need to be done
     return profileLoop;
}

public void Sortpoints()  //or any other method
{
    //...everything else
    List<CurveLoop> profile3 = new List<CurveLoop>();
    profile3.Add(CreateCurveloop(pointList1);
    profile3.Add(CreateCurveloop(pointList2);
    ....
    Solid loft = GeometryCreationUtilities.CreateLoftGeometry(profile3 ,options);
}

 

Does this answer your question?

Message 16 of 17

vanlion
Advocate
Advocate

Hi,

 

Finally the second one was the sollution. What i did wrong was the moment were i call the method in a method so everything was going double. By adding the code underneath at the begin were i collect the points the result is good!

 

List<CurveLoop> profile3 = new List<CurveLoop>();
profile3.Add(CreateCurveloop(sortPoints(pointsBK)));
profile3.Add(CreateCurveloop(sortPoints(pointsOK)));

Result:

 

Annotation 2019-05-08 121414.png

0 Likes
Message 17 of 17

vanlion
Advocate
Advocate

Last Question, when you do the same in Dynamo, creating a loft from,  you can create a directShape that isn't a solid

 

Annotation 2019-05-08 125848.pngAnnotation 2019-05-08 125611.png

 

Is this also possible?

 

Thanks

0 Likes