Sometimes the built-in tools for measuring in iLogic do seem a bit inadequate, and they aren't always a good fit for some of the stuff we try to use them for. It can take a bit of time to set-up, but it may pay off in the long run to create a set of custom reference Subs &/or Functions for measuring/comparing different specific types of geometry for these occasions.
In this case (which is likely simplified for testing purposes), it seems like you are comparing two regular 2d lines in a PlanarSketch. In this situation, we have several other built-in tools for comparing/measuring them, that you just have to dig a little deeper for. I created an example part file, and manually created a sketch on a plane and put two non-parallel lines on it that don't touch each other. Then I created this iLogic rule to compare the two lines. In this rule I isolated all the comparison work in a custom Function, and to keep it as useful as possible, I'm having that function return a NameValueMap (native to Inventor - could use a Dictionary or other collection type that uses Key/Value pairs). Then I use a simple multi-line MsgBox to display the results to the user. The resulting NameValueMap includes 4 name/value pairs (Parallel (Boolean), Perpendicular (Boolean), Angle (Double), and Distance (Double)).
Here's the iLogic rule code that I've got right now:
Sub Main
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oSketch As PlanarSketch = oPDef.Sketches.Item("Measure Test Sketch")
Dim oSketchLine1 As SketchLine = oSketch.SketchLines.Item(1)
Dim oSketchLine2 As SketchLine = oSketch.SketchLines.Item(2)
Dim oResult As NameValueMap = Line2dCompare(oSketchLine1, oSketchLine2)
MsgBox(oResult.Name(1) & " = " & oResult.Value(oResult.Name(1)) & vbCrLf & _
oResult.Name(2) & " = " & oResult.Value(oResult.Name(2)) & vbCrLf & _
oResult.Name(3) & " = " & oResult.Value(oResult.Name(3)) & vbCrLf & _
oResult.Name(4) & " = " & oResult.Value(oResult.Name(4)),,"RESULTS")
End Sub
Function Line2dCompare(oLin1 As SketchLine, oLin2 As SketchLine) As NameValueMap
Dim oResults As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oParallel, oPerpendicular As Boolean 'both False by default
Dim oAngle As Double
Dim oDist As Double
Dim oDir1 As UnitVector2d = oLin1.Geometry.Direction
Dim oDir2 As UnitVector2d = oLin1.Geometry.Direction
oAngle = oDir1.AngleTo(oDir2)
If oDir1.IsParallelTo(oDir2, .001) Then
oParallel = True
'or measure the distance between them and return that Double
oDist = oLin1.Geometry.DistanceTo(oLin2.Geometry.StartPoint)
ElseIf oDir1.IsPerpendicularTo(oDir2, .001) Then
oPerpendicular = True
If oLin1.Geometry.IntersectWithCurve(oLin2.Geometry).Count > 0 Then
'they intersect, so set oDist to zero
oDist = 0
Else
'you could attempt to measure the minimum distance between the two
Dim oD1 As Double = oLin1.Geometry.DistanceTo(oLin2.Geometry.StartPoint)
Dim oD2 As Double = oLin1.Geometry.DistanceTo(oLin2.Geometry.EndPoint)
oDist = Min(oD1, oD2)
End If
End If
If oParallel = False And oPerpendicular = False Then
'now attempt to get the 'minimum' distance between the two non parralel line segments
'since these are staight lines, this distance will be between start/end points, so compare them for minimum
Dim oL1Sp, oL1Ep, oL2Sp, oL2Ep As Point2d
oL1Sp = oLin1.StartSketchPoint.Geometry
oL1Ep = oLin1.EndSketchPoint.Geometry
oL2Sp = oLin2.StartSketchPoint.Geometry
oL2Ep = oLin2.EndSketchPoint.Geometry
Dim oSpDist As Double = oL1Sp.DistanceTo(oL2Sp) 'start point to start point (-)
Dim oEpDist As Double = oL1Ep.DistanceTo(oL2Ep) 'end point to end point (-)
Dim oSEDist As Double = oL1Sp.DistanceTo(oL2Ep) 'start point to end point (x)
oDist = MinOfMany(oSpDist, oEpDist, oSEDist)
End If
oResults.Add("Parallel", oParallel)
oResults.Add("Perpendicular", oPerpendicular)
oResults.Add("Angle", oAngle)
oResults.Add("Distance", oDist)
Return oResults
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)