FlatPattern.FindUsingRay example

FlatPattern.FindUsingRay example

i.rudd
Participant Participant
432 Views
5 Replies
Message 1 of 6

FlatPattern.FindUsingRay example

i.rudd
Participant
Participant

Hello,

 

I would like to know if somebody could give me an example of how to use FlatPattern.FindUsingRay method as I am not having success with it.

 

Nevertheless, I am being able to use SurfaceBody.FindUsingRay successfully. 

 

Thank you very much in advance!

 

Have a nice day.

 

0 Likes
Accepted solutions (1)
433 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor

Can you describe your requested workflow? What do you expect as result?

0 Likes
Message 3 of 6

i.rudd
Participant
Participant

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

 

0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor

Use FindUsingRay method for this purpose is overkill in my opinion. Try to use another approach.

1) Measure distance between top and bottom face

2) Z coordinate difference of range box (needs to be rounded)

3) Get thickness from SheetMetalComponentDefinition

 

 

 

Dim part As PartDocument = ThisDoc.Document
Dim smDef As SheetMetalComponentDefinition = part.ComponentDefinition
Dim flatPattern As FlatPattern = smDef.FlatPattern

'Distance between top and bottom faces
Dim topFace As Face = flatPattern.TopFace
Dim bottomFace As Face = flatPattern.BottomFace
Dim t1 As Double = ThisApplication.MeasureTools.GetMinimumDistance(topFace, bottomFace)
Logger.Debug(t1)

'Z coordinate difference of range box
Dim t2 As Double = Abs(flatPattern.RangeBox.MaxPoint.Z - flatPattern.RangeBox.MinPoint.Z)
Logger.Debug(t2)

'Get thickness from SheetMetalComponentDefinition
Dim t3 As Double = smDef.Thickness.ModelValue
Logger.Debug(t3)

 

 

 

 

Message 5 of 6

i.rudd
Participant
Participant

That is great. Thank you!

 

Out of curiosity, and for the next person that finds this post, would it be possible to get an example using FindusingRay for the flat pattern please? I wonder why I am not getting any points.

 

0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

 

Here it is. I hope it helps.

Dim part As PartDocument = ThisDoc.Document
Dim smDef As SheetMetalComponentDefinition = part.ComponentDefinition
Dim flatPattern As FlatPattern = smDef.FlatPattern


Dim rayStartPoint As Point = flatPattern.TopFace.PointOnFace
Dim rayDirection As UnitVector = ThisApplication.TransientGeometry.CreateUnitVector(0, 0, -1)
Dim radius As Double = 0.001
Dim foundEntities As ObjectsEnumerator
Dim locationPoints As ObjectsEnumerator
Dim findFirstOnly As Boolean = False

flatPattern.FindUsingRay(rayStartPoint, rayDirection, radius, foundEntities, locationPoints, findFirstOnly)

Logger.Debug("rayStartPoint = [{0:0.00}; {1:0.00}; {2:0.00}]", rayStartPoint.X, rayStartPoint.Y, rayStartPoint.Z)

Logger.Debug("foundEntities = {0}", foundEntities.Count)
For Each entity In foundEntities
	Dim entityType = [Enum].GetName(GetType(Inventor.ObjectTypeEnum), entity.Type )
	Logger.Debug("   {0}",  entityType)
Next

Logger.Debug("locationPoints = {0}", locationPoints.Count)
For Each entity In locationPoints
	Logger.Debug("   [{0:0.00}; {1:0.00}; {2:0.00}]", entity.X, entity.Y, entity.Z)
Next