Community
Hi Pablo,
It probably depends on the model, but in my tests the following code I wrote seemed to work fast enough:
Sub CheckIntersection() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument Dim wp1 As WorkPoint Dim wp2 As WorkPoint Set wp1 = doc.SelectSet(1) Set wp2 = doc.SelectSet(2) Dim sp As Point Set sp = wp1.Point Dim ep As Point Set ep = wp2.Point Dim dir As Vector Set dir = sp.VectorTo(ep) Dim dist As Double dist = sp.DistanceTo(ep) Dim filter(1 To 1) As SelectionFilterEnum filter(1) = kPartFaceFilter Dim pts As Variant Dim oe As ObjectsEnumerator Set oe = doc.ComponentDefinition.FindUsingVector( _ sp, dir.AsUnitVector, filter, , , , pts) Dim i As Integer For i = 1 To oe.Count Dim pt As Point Set pt = pts(i) ' If we are going beyond the end point then ' let's stop If sp.DistanceTo(pt) > dist Then Exit For End If Dim f As Face Set f = oe(i) Dim se As SurfaceEvaluator Set se = f.Evaluator Dim ptData() As Double pt.GetPointData ptData Dim normals() As Double se.GetNormalAtPoint ptData, normals Dim n As Vector Set n = ThisApplication.TransientGeometry.CreateVector() Call n.PutVectorData(normals) ' Check if the section up till the intersection point ' was inside a solid or outside ' If the face's normal is the same direction ' as we are going, then we are leaving the solid through ' this face Dim isInside As Boolean isInside = n.DotProduct(dir) > 0# Dim length As Double Select Case i Case 1: length = sp.DistanceTo(pt) Case oe.Count: length = ep.DistanceTo(pt) Case Else: length = pt.DistanceTo(pts(i - 1)) End Select Debug.Print str(length) + " section inside solid = " + str(isInside) Next End Sub
I hope this helps.
Cheers,