Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Finding opposite face

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
kulkarniyh12.mech
959 Views, 3 Replies

Finding opposite face

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

3 REPLIES 3
Message 2 of 4
ekinsb
in reply to: kulkarniyh12.mech

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

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 4
kulkarniyh12.mech
in reply to: ekinsb

This worked. I guess, my UnitVector and Radius specification was not correct...Thanks a lot
Message 4 of 4
Maxim-CADman77
in reply to: ekinsb

@ekinsb 

Ok. You've found the distance to opposite face but what  about  the face itself, how can i find it via distance?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report