The steps are marked in the code below:
- Step 1: Getting areas and sorting all faces;
- Step 2: Finding the face with the largest area and the face with the second largest area. Getting the minimum distance between them.
- Step 3: Reading all edges of the outer face;
- Step 4: Reading all edges of the inner face;
- Step 5: Reading all faces of the current edge (Edges(iE1));
- Step 6: Reading all faces of the current edge (Edges(iE2));
- Step 7: Distance comparison between current faces and dThick;
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDoc As PartDocument = oInvApp.ActiveDocument
Dim oMT As MeasureTools = oInvApp.MeasureTools
Dim oBody As SurfaceBody = oDoc.ComponentDefinition.SurfaceBodies(1)
'[ Step 1
Dim dArreaList As New List(Of Double)
For i As Integer = 1 To oBody.Faces.Count
dArreaList.Add(oBody.Faces(i).Evaluator.Area)
Next
dArreaList.Sort()']
Dim oFaceOutMax, oFaceInMax As Face
Dim oEdgeOut, oEdgeIn As Edge
'[ Step 2
For i As Integer = 1 To oBody.Faces.Count
If oBody.Faces(i).Evaluator.Area = dArreaList(dArreaList.Count - 1) Then
oFaceOutMax = oBody.Faces(i)
Else If oBody.Faces(i).Evaluator.Area = dArreaList(dArreaList.Count - 2) Then
oFaceInMax = oBody.Faces(i)
End If
Next
Dim dThick As Double = oMT.GetMinimumDistance(oFaceOutMax, oFaceInMax)']
'[ Step 3
For iE1 As Integer = 1 To oFaceOutMax.Edges.Count
'[ Step 4
For iE2 As Integer = 1 To oFaceInMax.Edges.Count
'[ Step 5
For iF1 As Integer = 1 To oFaceOutMax.Edges(iE1).Faces.Count
If oFaceOutMax.Edges(iE1).Faces(iF1) Is oFaceOutMax Then Continue For 'A face from the edge is not an outside face
'[ Step 6
For iF2 As Integer = 1 To oFaceInMax.Edges(iE2).Faces.Count
If oFaceInMax.Edges(iE2).Faces(iF2) Is oFaceInMax Then Continue For 'A face from the edge is not an inside face
If oFaceOutMax.Edges(iE1).Faces(iF1) Is oFaceInMax.Edges(iE2).Faces(iF2) Then Continue For 'Shared face
'[ Step 7
If EqualWithinTolerance(oMT.GetMinimumDistance(oFaceOutMax.Edges(iE1).Faces(iF1),
oFaceInMax.Edges(iE2).Faces(iF2)), dThick, 0.001) Then
oEdgeOut = oFaceOutMax.Edges(iE1) : oEdgeIn = oFaceInMax.Edges(iE2)
GoTo SkipSearch
End If']
Next iF2']
Next iF1']
Next iE2']
Next iE1']
SkipSearch :
oDoc.SelectSet.Select(oEdgeOut) 'Outer edge
oDoc.SelectSet.Select(oEdgeIn) 'Inner edge
If you have a Г-profile of the part, you do not need to measure the distances, but if you have a C-profile, you definitely need to measure the distances.
In any case, it is very difficult to write code that will understand all possible variations of a part.
