Sub Main Dim oFAM As New FaceAngleMeasurer(ThisApplication) Dim dAngle As Double = oFAM.GetAngleBetweenFaces(oFace1, oFace2) dAngle = (dAngle * (180 / Math.PI)) 'convert radians to degrees Dim sReport As String = "Angle = " & dAngle.ToString & " deg" If oFAM.FacesAreParallel Then sReport &= vbCrLf & "Faces were parallel" Dim oCommonEdge As Edge = oFAM.CommonEdge If oCommonEdge Is Nothing Then sReport &= vbCrLf & "Common Edge - Not Found" Else sReport &= vbCrLf & "Common Edge - Found" If EdgeIsConcave(oCommonEdge) Then sReport &= vbCrLf & "Common Edge - Is Concave" ElseIf EdgeIsConvex(oCommonEdge) Then sReport &= vbCrLf & "Common Edge - Is Convex" Else sReport &= vbCrLf & "Common Edge - Is Neither Concave nor Convex" End If End If MsgBox(sReport, vbInformation, "iLogic") End Sub Private Function EdgeIsConcave(oEdgeToCheck As Inventor.Edge) As Boolean For Each oEdge As Inventor.Edge In oEdgeToCheck.Parent.ConcaveEdges If oEdge Is oEdgeToCheck Then Return True Next Return False End Function Private Function EdgeIsConvex(oEdgeToCheck As Inventor.Edge) As Boolean For Each oEdge As Inventor.Edge In oEdgeToCheck.Parent.ConvexEdges If oEdge Is oEdgeToCheck Then Return True Next Return False End Function Class FaceAngleMeasurer Private _InvApp As Inventor.Application Private _FacesAreParallel As Boolean Private _CommonEdge As Inventor.Edge Private _VirtualIntersection As Inventor.Line Sub New(InventorApp As Inventor.Application) _InvApp = InventorApp End Sub Public Function GetAngleBetweenFaces(Optional oFace1 As Inventor.Face = Nothing, _ Optional oFace2 As Inventor.Face = Nothing) As Double If oFace1 Is Nothing Then oFace1 = PickPlanarFace If oFace1 Is Nothing Then Return 0.0 If oFace2 Is Nothing Then oFace2 = PickPlanarFace If oFace2 Is Nothing Then Return 0.0 Dim oEdgeDirection As UnitVector = Nothing Dim oCommonEdge As Edge = GetCommonEdge(oFace1, oFace2) If (oCommonEdge IsNot Nothing) AndAlso (TypeOf oCommonEdge.Geometry Is LineSegment) Then Dim oLineSegment As LineSegment = oCommonEdge.Geometry oEdgeDirection = oLineSegment.Direction Else Dim oLine As Inventor.Line = GetPlanarIntersectionLine(oFace1, oFace2) If oLine IsNot Nothing Then oEdgeDirection = oLine.Direction End If If oEdgeDirection Is Nothing Then Return 0.0 Dim oNorm1 As UnitVector = GetFaceNormal(oFace1) Dim oNorm2 As UnitVector = GetFaceNormal(oFace2) If oNorm1.IsParallelTo(oNorm2) Then _FacesAreParallel = True Return 0.0 Else _FacesAreParallel = False 'use CrossProduct to get 2 perpendicular directions pointing away from edge Dim oDir1 As UnitVector = oNorm1.CrossProduct(oEdgeDirection) Dim oDir2 As UnitVector = oEdgeDirection.CrossProduct(oNorm2) Return oDir1.AngleTo(oDir2) End If Return 0.0 End Function Private Function PickPlanarFace(Optional sPrompt As String = Nothing) As Inventor.Face If sPrompt Is Nothing OrElse sPrompt = "" Then sPrompt = "Select Planar Face - or press ESC key to exit" Dim eFilter As SelectionFilterEnum = SelectionFilterEnum.kPartFacePlanarFilter Dim oFace As Face = _InvApp.CommandManager.Pick(eFilter, sPrompt) Return oFace End Function Private Function GetCommonEdge(oFace1 As Inventor.Face, oFace2 As Inventor.Face) As Inventor.Edge For Each oEdge As Inventor.Edge In oFace1.Edges For Each oOtherFace In oEdge.Faces If oOtherFace Is oFace2 Then _CommonEdge = oEdge Return oEdge End If Next oOtherFace Next oEdge Return Nothing End Function Private Function GetPlanarIntersectionLine(oFace1 As Inventor.Face, oFace2 As Inventor.Face) As Inventor.Line If (TypeOf oFace1.Geometry Is Plane) AndAlso (TypeOf oFace2.Geometry Is Plane) Then Dim oP1 As Inventor.Plane = oFace1.Geometry Dim oP2 As Inventor.Plane = oFace2.Geometry If Not oP1.IsParallelTo(oP2) Then Dim oLine As Inventor.Line = oP1.IntersectWithPlane(oP2, 0.001) _VirtualIntersection = oLine Return oLine End If End If Return Nothing End Function Private Function GetFaceNormal(oFace As Inventor.Face) As Inventor.UnitVector If TypeOf oFace.Geometry Is Inventor.Plane Then Dim oPlane As Inventor.Plane = oFace.Geometry Return oPlane.Normal Else Dim oPt() As Double = {} : Dim oNorm() As Double = {} oFace.PointOnFace.GetPointData(oPt) oFace.Evaluator.GetNormalAtPoint(oPt, oNorm) Return _InvApp.TransientGeometry.CreateUnitVector(oNorm(0), oNorm(1), oNorm(2)) End If End Function Public ReadOnly Property CommonEdge As Inventor.Edge Get Return _CommonEdge End Get End Property Public ReadOnly Property VirtualIntersection As Inventor.Line Get Return _VirtualIntersection End Get End Property Public ReadOnly Property FacesAreParallel As Boolean Get Return _FacesAreParallel End Get End Property End Class