Using AddForSolid with SketchLInes.AddByTwoPoints

Using AddForSolid with SketchLInes.AddByTwoPoints

bravaiser
Enthusiast Enthusiast
1,312 Views
9 Replies
Message 1 of 10

Using AddForSolid with SketchLInes.AddByTwoPoints

bravaiser
Enthusiast
Enthusiast

The main issue here is that once I create a set of SketchLines I want to create the Profile but it is throwing an error, can anyone give me a suggestion.
 
oSketch.SketchLines.AddByTwoPoints(oPoint2d_a, oPoint2d_b); 
oSketch.SketchLines.AddByTwoPoints(oPoint2d_b, oPoint2d_c);
oSketch.SketchLines.AddByTwoPoints(oPoint2d_c, oPoint2d_d);
oSketch.SketchLines.AddByTwoPoints(oPoint2d_d, oPoint2d_e);
oSketch.SketchLines.AddByTwoPoints(oPoint2d_e, oPoint2d_a);
 
oProfile = oSketch.Profiles.AddForSolid(); //here is the problem
 
thank you 

0 Likes
Accepted solutions (1)
1,313 Views
9 Replies
Replies (9)
Message 2 of 10

ekinsb
Alumni
Alumni
Accepted solution

What are your point variables referencing?  If they're existing sketch points then I would expect it to work.  If they're Point objects then I can see why it is failing.  The reason is that the code will be creating 5 lines that aren't connected.  They might visibly be connected but when creating a profile they must be connected by either sharing the same sketch point or through constraints.

 

Assuming they are Point objects, this variation of your program should work.  It's using the sketch point from the last line as the first point of the next line so everything will be connected.

 

SketchLine firstLine;

SketchLine lastLine;

firstLine = oSketch.SketchLines.AddByTwoPoints(oPoint2d_a, oPoint2d_b); 
lastLine = oSketch.SketchLines.AddByTwoPoints(firstLine.EndSketchPoint, oPoint2d_c);
lastLine = oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, oPoint2d_d);
lastLine = oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, oPoint2d_e);
oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, firstLine.StartSketchPoint);

 

oProfile = oSketch.Profiles.AddForSolid();


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 10

bravaiser
Enthusiast
Enthusiast

thnak you for the suggestion I ended up using something like this 

 

lineOne =  oSketch.SketchLines.AddByTwoPoints(oPoint2d_a, oPoint2d_b);      
lineTwo = oSketch.SketchLines.AddByTwoPoints(oPoint2d_b, oPoint2d_c);
lineThree = oSketch.SketchLines.AddByTwoPoints(oPoint2d_c, oPoint2d_d);
lineFour = oSketch.SketchLines.AddByTwoPoints(oPoint2d_d, oPoint2d_e);
lineFive = oSketch.SketchLines.AddByTwoPoints(oPoint2d_e, oPoint2d_a);

lineOne.EndSketchPoint.Merge(lineTwo.StartSketchPoint);
lineTwo.EndSketchPoint.Merge(lineThree.StartSketchPoint);
lineThree.EndSketchPoint.Merge(lineFour.StartSketchPoint);
lineFour.EndSketchPoint.Merge(lineFive.StartSketchPoint);
lineFive.EndSketchPoint.Merge(lineOne.StartSketchPoint);

 

0 Likes
Message 4 of 10

bravaiser
Enthusiast
Enthusiast

Brian

 

I am having a performance issue with this function, my call to create this sketchlines are inside a loop, there are no gaps in my code, as far as I can tell. When I check for time utilization in this part of the code, the creation of the elements in my pattern takes longer and longer. What can I do to speed up the process.

 

thank you for any advice

 

for (int i=0; i< numberOfElements.Count(); i++){

...

                        lineOne =  oSketch.SketchLines.AddByTwoPoints(oPoint2d_a, oPoint2d_b);  
                        lineTwo = oSketch.SketchLines.AddByTwoPoints(oPoint2d_b, oPoint2d_c);
                        lineThree = oSketch.SketchLines.AddByTwoPoints(oPoint2d_c, oPoint2d_d);
                        lineFour = oSketch.SketchLines.AddByTwoPoints(oPoint2d_d, oPoint2d_e);
                        lineFive = oSketch.SketchLines.AddByTwoPoints(oPoint2d_e, oPoint2d_a);

                        lineOne.EndSketchPoint.Merge(lineTwo.StartSketchPoint);
                        lineTwo.EndSketchPoint.Merge(lineThree.StartSketchPoint);
                        lineThree.EndSketchPoint.Merge(lineFour.StartSketchPoint);
                        lineFour.EndSketchPoint.Merge(lineFive.StartSketchPoint);
                        lineFive.EndSketchPoint.Merge(lineOne.StartSketchPoint);

....

oProfile = oSketch.Profiles.AddForSolid();


}

 

0 Likes
Message 5 of 10

ekinsb
Alumni
Alumni

With the few number of lines you're creating, I don't know if the line creation is what's taking the time.  What else is in that loop; sketch creation, feature creation? 

 

If you were creating a large sketch, then using the Sketch.DeferUpdates property can help.  Set this property to True, create your sketch entities, and then set it back to False.  But with the small number of lines you're creating I don't know if this will help that much.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 10

bravaiser
Enthusiast
Enthusiast

I am actually creating hundreds of elements formed with this few sketchlines, then create a solid and perform a protrusion. I create a pentagon on a surface and then a protrusion, hundreds of times, the process seams to work but it takes 18 min for 290 elements. That is a long time, analysing the code, this part eats 30% of the time, then protrusion other 30%. But it seams like is reading all the profiles each time before creates a new one, and also for the protrusions, as if is reading all the protrusions in the geometry, so more elements more time...

 

Let me try your suggestion in the mean time... thank you Brian

 

 

0 Likes
Message 7 of 10

naresh_kalyan
Advocate
Advocate

Greetings!!!

 

Hi all, after a year again I'm into Inventor Customization. Here, I have few questions as per this thread.

 

If a sketch contains multiple lines, can we write a For loop to creating them. If so, how to Merge the points to get the profile.

 

LineA.StartSketchPoint.Merge(LineB.StartSketchPoint) .. Here, I'm limiting to LineA, LineB, LineC and LineD. So that, I could Merge the points for retrieving the profile, which is used to create Extrude or Revolve etc.

 

Anyone's help would be greatly appreciated, either in C#.net ot VB.net.

 

Thanking you all...

 

Regards

Naresh Kalyan

0 Likes
Message 8 of 10

naresh_kalyan
Advocate
Advocate

Even we tried in this way, But still not merging the lines.

 

If oSketch.SketchLines.Item(i).StartSketchPoint.Geometry.X = oSketch.SketchLines.Item(j).StartSketchPoint.Geometry.X Then

If oSketch.SketchLines.Item(i).StartSketchPoint.Geometry.Y = oSketch.SketchLines.Item(j).StartSketchPoint.Geometry.Y Then


oSketch.SketchLines.Item(i).StartSketchPoint.Merge(oSketch.SketchLines.Item(j).StartSketchPoint)

 

end if

end if

 

 

Regards

Naresh Kalyan

0 Likes
Message 9 of 10

naresh_kalyan
Advocate
Advocate

Hi all,

It got resolved by using couple of For loops. Thought it might be useful for anyone who's facing similar challenge.

 

Public i, j, NumLines as long

 

 

For i = 1 To NumLines

For j = i + 1 To NumLines


If i <> j Then

 

If osketch.SketchLines.Item(i).StartSketchPoint.Geometry.X = osketch.SketchLines.Item(j).StartSketchPoint.Geometry.X And _
osketch.SketchLines.Item(i).StartSketchPoint.Geometry.Y = osketch.SketchLines.Item(j).StartSketchPoint.Geometry.Y Then
Call osketch.SketchLines.Item(i).StartSketchPoint.Merge(osketch.SketchLines.Item(j).StartSketchPoint)


ElseIf osketch.SketchLines.Item(i).EndSketchPoint.Geometry.X = osketch.SketchLines.Item(j).StartSketchPoint.Geometry.X And _
osketch.SketchLines.Item(i).EndSketchPoint.Geometry.Y = osketch.SketchLines.Item(j).StartSketchPoint.Geometry.Y Then
Call osketch.SketchLines.Item(i).EndSketchPoint.Merge(osketch.SketchLines.Item(j).StartSketchPoint)

ElseIf osketch.SketchLines.Item(i).StartSketchPoint.Geometry.X = osketch.SketchLines.Item(i).EndSketchPoint.Geometry.X And _
osketch.SketchLines.Item(i).StartSketchPoint.Geometry.Y = osketch.SketchLines.Item(j).EndSketchPoint.Geometry.Y Then
Call osketch.SketchLines.Item(i).StartSketchPoint.Merge(osketch.SketchLines.Item(j).EndSketchPoint)

ElseIf osketch.SketchLines.Item(i).EndSketchPoint.Geometry.X = osketch.SketchLines.Item(j).EndSketchPoint.Geometry.X And _
osketch.SketchLines.Item(i).EndSketchPoint.Geometry.Y = osketch.SketchLines.Item(j).EndSketchPoint.Geometry.Y Then
Call osketch.SketchLines.Item(i).EndSketchPoint.Merge(osketch.SketchLines.Item(j).EndSketchPoint)

End If


End If

Next


odoc.Save()

Next

Next

 

 

0 Likes
Message 10 of 10

maartenvandooren
Explorer
Explorer

I had problems with AddForSolid.
Merge is extra programming and I don't like that.

This works perfect!

firstLine = oSketch.SketchLines.AddByTwoPoints(oPoint2d_a, oPoint2d_b); 
lastLine = oSketch.SketchLines.AddByTwoPoints(firstLine.EndSketchPoint, oPoint2d_c);
lastLine = oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, oPoint2d_d);
lastLine = oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, oPoint2d_e);
oSketch.SketchLines.AddByTwoPoints(lastLine.EndSketchPoint, firstLine.StartSketchPoint);

TY! Brian

0 Likes