I have a solid body made by a single feature Extrude. A simple plate. I wish to find face pair, of two bigger faces, which are opposite of each other.
For a function, I pass one of the big faces, and wish to find opposite face of it, within same body. Tried following logic but does not work:
Private Function findDistanceToOppsiteFace(ByRef face As Inventor.Face, ByRef feat As PartFeature) As Double
findDistanceToOppsiteFace = 0.0
Dim origin As Inventor.Point = face.PointOnFace
Dim pt(2) As Double
Dim n(2) As Double
pt(0) = origin.X : pt(1) = origin.Y : pt(2) = origin.Z
face.Evaluator.GetNormalAtPoint(pt, n)
Dim normal As Inventor.UnitVector = _invApp.TransientGeometry.CreateUnitVector(n(0), n(1), n(2))
Dim body As SurfaceBody = feat.SurfaceBodies.Item(1)
Dim radius As Double = Math.Sqrt(face.Evaluator.Area) * 2.0
Dim objects As ObjectsEnumerator
Dim pts As ObjectsEnumerator
Dim objtypes(0 To 1) As SelectionFilterEnum
objtypes(1) = SelectionFilterEnum.kPartFaceFilter
'body.FindUsingRay(origin, normal, radius, objects, pts, True)
objects = m_partDoc.ComponentDefinition().FindUsingVector(origin, normal, objtypes)
findDistanceToOppsiteFace = _invApp.MeasureTools.GetMinimumDistance(origin, objects.Item(1))
End Function
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
You were very close. Here's some VBA code that works.
Public Sub TestFindDistance() Dim planeFace As face Set planeFace = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Pick a planar face.") Dim dist As Double dist = findDistanceToOppositeFace(planeFace) MsgBox "Distance: " & dist End Sub Private Function findDistanceToOppositeFace(ByRef face As Inventor.face) As Double findDistanceToOppositeFace = 0 Dim origin As Inventor.Point Set origin = face.PointOnFace Dim pt(2) As Double pt(0) = origin.X: pt(1) = origin.Y: pt(2) = origin.Z ' Get the normal of the face and create a vector in the reverse direction ' because the face normal points out of the solid. Dim n(2) As Double Call face.Evaluator.GetNormalAtPoint(pt, n) Dim normal As Inventor.UnitVector Set normal = ThisApplication.TransientGeometry.CreateUnitVector(-n(0), -n(1), -n(2)) ' Get the parent body. Dim body As SurfaceBody Set body = face.Parent ' Find all faces intersected by a ray. Dim objects As ObjectsEnumerator Dim pts As ObjectsEnumerator Call body.FindUsingRay(origin, normal, 0.001, objects, pts, True) ' Calculate the distance using the second face because the first one will ' be the original input face. findDistanceToOppositeFace = ThisApplication.MeasureTools.GetMinimumDistance(origin, objects.Item(2)) End Function
Ok. You've found the distance to opposite face but what about the face itself, how can i find it via distance?