Hello Michael,
Thank you for the quick reply.
Goal: calculate with a VBA rule the thickness of an active metal sheet part by measuring the distance of the intersecting points returned by the FindUsingRay method for a flat pattern.
Here is my code (no intersection points are found). See test part attached. Thank you!
Sub Main()
'Get the Active document(ipt, idw, ipn, iam)
Dim oDoc As Document = ThisApplication.ActiveDocument
'Get the FlatPattern (Assumption: part is a metal sheet)
Dim oFlatPattern As FlatPattern = oDoc.ComponentDefinition.FlatPattern
''Find all Points that intersect the flat pattern with FindUsingRay. Define needed inputs:
'1) Starting Point:
'Define the flat pattern base face
Dim oFpFace As Face = oFlatPattern.BaseFace
'Define a (random) point on the flat pattern face
Dim oPt1 As Point = oFpFace.PointOnFace
'2) Ray direction
'Create unit vector normal to flat pattern base face (Assuming always in Z direction)
Dim oTrans As TransientGeometry = ThisApplication.TransientGeometry
Dim n As UnitVector = oTrans.CreateUnitVector(0, 0, 1)
'3) Objects found
Dim oObjs As ObjectsEnumerator
'4) Intersecting points
Dim oPoints As ObjectsEnumerator
Call oFlatPattern.FindUsingRay(oPt1, n, 0, oObjs, oPoints, 0)
'Flip normal in case no points are found
If oPoints.Count = 0 Then
n.X = -n.X
n.Y = -n.Y
n.Z = -n.Z
Call oFlatPattern.FindUsingRay(oPt1, n, 0, oObjs, oPoints, 0)
End If
MsgBox("oPoints count = " & oPoints.Count)
'If points are found: Visualize first and last point of intersection and give the metal sheet thickness
If Not oPoints.Count = 0 Then
Dim oPnt1 As Point = oTrans.CreatePoint(oPt1.X, oPt1.Y, oPt1.Z)
Dim oPnt2 As Point = oTrans.CreatePoint(oPoints(oPoints.Count).X, oPoints(oPoints.Count).Y, oPoints(oPoints.Count).Z)
Dim oWorkPoint1 As WorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(oPnt1, False)
Dim oWorkPoint2 As WorkPoint = oDoc.ComponentDefinition.WorkPoints.AddFixed(oPoints(oPoints.Count), False)
MsgBox("Metal sheet thickness = " & oPnt1.distanceto(oPoints(oPoints.Count)))
End If
End Sub