By Barbara Han
There can be many ways to compute a face's normal using the geometric information provided by the Inventor objects. However, the best way to compute a normal using the API is to use the Face.Evaluator object.
Here is a sample that iteratesthroughl faces of a SurfaceBody and output the normal vectors for the faces that are planar.
VBA sample:
Public Sub ComputePlanarFacesNormals()
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim oFaces As Faces
Set oFaces = oPartDoc.ComponentDefinition.SurfaceBodies(1).Faces
Dim Params(1 To 2) As Double
Dim Normals(1 To 3) As Double
'If Faces is planar, then the Normal wil be the same all over the face
Params(1) = 0
Params(2) = 0
Dim index As Long
index = 1
Dim oFace As Face
For Each oFace In oFaces
'Ensures Face is planar
If (TypeOf oFace.Geometry Is Plane) Then
Call oFace.Evaluator.GetNormal(Params, Normals)
Dim oUnitNormal As UnitVector
Set oUnitNormal = ThisApplication.TransientGeometry.CreateUnitVector(Normals(1), Normals(2), Normals(3))
Debug.Print "Planar Face[" & index & "] Normal: [" & oUnitNormal.X & ", " & oUnitNormal.Y & ", " & oUnitNormal.Z & "]"
index = index + 1
End If
Next
End Sub
VB.NET sample:
Private SubComputePlanarFacesNormals()
Try
Dim oPartDoc As PartDocument = m_inventorApp.ActiveDocument
Dim oFaces As Faces
oFaces = oPartDoc.ComponentDefinition.SurfaceBodies(1).Faces
Dim Params(0 To 3) As Double
Dim Normals(0 To 3) As Double
'If Faces is planar, then the Normal wil be the same all over the face
Params(1) = 0
Params(2) = 0
Dim index As Long = 1
Dim oFace As Face
For Each oFace In oFaces
'Ensures Face is planar
If (TypeOf oFace.Geometry Is Plane) Then
Call oFace.Evaluator.GetNormal(Params, Normals)
Dim oUnitNormal As UnitVector
oUnitNormal = m_inventorApp.TransientGeometry.CreateUnitVector(Normals(1), Normals(2), Normals(3))
System.Diagnostics.Debug.Write("Planar Face[" & index & "] Normal: [" & oUnitNormal.X & ", " & oUnitNormal.Y & ", " & oUnitNormal.Z & "]" & vbCrLf)
index = index + 1
End If
Next
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub