Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding intersections of lines and arcs with API

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
mucahid_tadik1
557 Views, 6 Replies

Finding intersections of lines and arcs with API

Hello, I am working on the intersection points of lines.

 

adep3d_0-1697636171649.png

 

I can find the intersection of 2 lines with the following code

SketchLine Line1 = sketch.SketchLines[1]
SketchLine Line2 = sketch.SketchLines[2]
var intersectWithCurve = Line1.Geometry.IntersectWithCurve(Line2.Geometry);
if (intersectWithCurve!=null){
   foreach (var o in intersectWithCurve){
       if (o is Point2d pt2d){
           Console.WriteLine(pt2d.X);
           Console.WriteLine(pt2d.Y);
       }
    }
}

 

So how can I find the intersection point of 2 arches? The IntersectWithCurve method is not present in the arc.

adep3d_1-1697636536239.png

 

6 REPLIES 6
Message 2 of 7

Hi @mucahid_tadik1 . This is an example of a possible solution (iLogic):

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches(1)
oSketch.Edit()
Dim oArc1 As SketchArc = oSketch.SketchArcs(1)
Dim oArc2 As SketchArc = oSketch.SketchArcs(2)
Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
Dim oSketchPoint As SketchPoint
oSketchPoint = oSketch.SketchPoints.Add(oPoint)
Call oSketch.GeometricConstraints.AddCoincident(oSketchPoint, oArc1)
Call oSketch.GeometricConstraints.AddCoincident(oSketchPoint, oArc2)
oSketch.ExitEdit()

 

Next, you can locate the point and delete it.

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 7

Hi @Andrii_Humeniuk , thank you for your answer, but this is not exactly the result I want to achieve, it is to move the lines to the intersection points of the arches as if trimming.

 

The full code is like this

foreach (SketchLine Line in sketch.SketchLines)
{
    foreach (SketchLine Line2 in sketch.SketchLines)
    {
        if (Line.Equals(Line2))
        {
            continue;
        }
        var intersectWithCurve = Line.Geometry.IntersectWithCurve(Line2.Geometry);
        if (intersectWithCurve!=null)
        {
            foreach (var o in intersectWithCurve)
            {
                if (o is Point2d pt2d)
                {
                    var distanceFromStart = Line.StartSketchPoint.Geometry.DistanceTo(pt2d);
                    var distanceFromEnd = Line.EndSketchPoint.Geometry.DistanceTo(pt2d);
                    if (distanceFromStart < distanceFromEnd)
                    {
                        Line.StartSketchPoint.MoveTo(pt2d);

                        var geometricConstraints = Line.Parent.GeometricConstraints;
                        geometricConstraints.AddCoincident(Line.StartSketchPoint as SketchEntity, Line2 as SketchEntity);
                    }
                    else
                    {
                        Line.EndSketchPoint.MoveTo(pt2d);

                        var geometricConstraints = Line.Parent.GeometricConstraints;
                        geometricConstraints.AddCoincident(Line.EndSketchPoint as SketchEntity, Line2 as SketchEntity);
                    }
                }
            }
        }
    }
}

 I move the parts of the lines that are outside as if I were trimming and create a conflict.

adep3d_0-1697690391893.png

 

I want to do the same application in arch, but there is no IntersectWithCurve method for arch. I'm looking for an alternative solution.

Message 4 of 7

This method has only one drawback, when overlaying dependencies between SketchPoint and SketchArc, the second can move. Therefore, I recommend that you lock your arches before doing this, and then unlock them if that is important to you.

ArcToArc.png

Sub main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oTG As TransientGeometry = oInvApp.TransientGeometry
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches(1)
	oSketch.Edit()
	Dim oArc1 As SketchArc = oSketch.SketchArcs(1)
	Dim oArc2 As SketchArc = oSketch.SketchArcs(2)
	Dim oPoint As Point2d = oTG.CreatePoint2d(0,0)
	Dim oSketchPoint As SketchPoint = oSketch.SketchPoints.Add(oPoint)
	Call oSketch.GeometricConstraints.AddCoincident(oSketchPoint, oArc1)
	Call oSketch.GeometricConstraints.AddCoincident(oSketchPoint, oArc2)
	oPoint.X = oSketchPoint.Geometry.X
	oPoint.Y = oSketchPoint.Geometry.Y
	Call oSketch.GeometricConstraints.AddCoincident(oArc2, ChangePointToArc(oArc1, oPoint))
	Call oSketch.GeometricConstraints.AddCoincident(oArc1, ChangePointToArc(oArc2, oPoint))
	oSketch.ExitEdit()
End Sub

Private Function ChangePointToArc(oArc As SketchArc, oPoint As Point2d) As SketchPoint
	Dim dDist1 As Double = oArc.StartSketchPoint.Geometry.DistanceTo(oPoint)
	Dim dDist2 As Double = oArc.EndSketchPoint.Geometry.DistanceTo(oPoint)
	Dim oSketch As PlanarSketch = oArc.Parent
	If dDist1 < dDist2 Then
		oArc.StartSketchPoint.MoveTo(oPoint)
		Return oArc.StartSketchPoint
	Else
		oArc.EndSketchPoint.MoveTo(oPoint)
		Return oArc.EndSketchPoint
	End If
End Function

 

Andrii Humeniuk - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 5 of 7

For this purpose you can use MeasureTools.GetMinimumDistance method.

The same code you can use to look for intersection point of any relevant entities in 2D and 3D space

Here is the sample for arcs in active sketch:

Dim activeSketch As Sketch = ThisApplication.ActiveEditObject
Dim arc1 As SketchArc = activeSketch.SketchArcs(1)
Dim arc2 As SketchArc = activeSketch.SketchArcs(2)

Dim context As NameValueMap

Dim dist As Double = ThisApplication.MeasureTools.GetMinimumDistance(arc1.Geometry, arc2.Geometry, kNoInference, kNoInference, context)
Logger.Debug(dist)
If dist = 0 Then
	Dim found = context.Value("IntersectionFound")
	Dim intersectionPoint  As Point2d = context.Value("IntersectionPoint")
	Logger.Debug("{0:N2}, {1:N2}", intersectionPoint.X, intersectionPoint.Y)
End If

 

Message 6 of 7

Hi @Michael.Navara , Thank you very much for teaching this method.

Message 7 of 7

Hi again,
While trying to get an intersection point with the MeasureTools.GetMinimumDistance method, I saw that it could only get a single intersection point. How can I reach the 2nd intersection point in an example like the one in the picture?

 

lineandarc.PNG

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report