Count number of holes in model which are created with Sketch and Extrude option

Hi,

I want to Find the no of Holes in the Model which i have created with Sketch(Circle) and Extrude option and i want sort them by Diameter. Could someone please help me with this.

Thanks,

Try the following journal:

'NXJournaling.com
'February 16, 2021

'find holes created with extrude
'report number of each size

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module5

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Const DecimalPlaces As Integer = 3

Dim bodyMostFaces As Body = Nothing
Dim numFaces As Integer = 0
For Each aBody As Body In theSession.Parts.Work.Bodies
Dim faceCount As Integer = aBody.GetFaces.Length
If faceCount > numFaces Then
bodyMostFaces = aBody
End If
Next

Dim dicHoles As New SortedDictionary(Of String, Integer)
Dim theFaceRadius As Double

For Each aFace As Face In bodyMostFaces.GetFaces
If IsHoleFace(aFace, theFaceRadius) Then
If Not FaceFromExtrude(aFace) Then
Continue For
End If
'calculate diameter, round value, add to dictionary
Dim dia As String = (theFaceRadius * 2).ToString("F" & DecimalPlaces.ToString)
'lw.WriteLine("dia: " & dia)
If dicHoles.ContainsKey(dia) Then
dicHoles.Item(dia) += 1
Else
dicHoles.Add(dia, 1)
End If
End If
Next

'report what we found
lw.WriteLine("holes made with extrude command:")
For Each kvp As KeyValuePair(Of String, Integer) In dicHoles
lw.WriteLine("hole diameter: " & kvp.Key & ", qty: " & kvp.Value.ToString)
Next

lw.Close()

End Sub

Function IsHoleFace(ByVal cylindricalFace As Face, ByRef faceMajorRadius As Double) As Boolean

'ask face type
Dim faceType As Integer
theUfSession.Modl.AskFaceType(cylindricalFace.Tag, faceType)
Select Case faceType
Case Is = UFConstants.UF_MODL_CYLINDRICAL_FACE
'so far, so good
Case Else
Return False
End Select

'find cylindrical face axis and point on the axis
Dim axisPt(2) As Double
Dim axisDir(2) As Double
Dim bbox(5) As Double
'Dim faceMajorRadius As Double
Dim faceMinorRadius As Double
Dim normalReversed As Integer
theUfSession.Modl.AskFaceData(cylindricalFace.Tag, faceType, axisPt, axisDir, bbox, faceMajorRadius, faceMinorRadius, normalReversed)

'get a u,v location on the face
Dim faceParm(1) As Double
Dim faceParmPt(2) As Double
theUfSession.Modl.AskFaceParm(cylindricalFace.Tag, axisPt, faceParm, faceParmPt)

'get face normal at point on face
Dim u1(2) As Double
Dim u2(2) As Double
Dim v1(2) As Double
Dim v2(2) As Double
Dim faceNorm(2) As Double
Dim principalRadii(1) As Double
theUfSession.Modl.AskFaceProps(cylindricalFace.Tag, faceParm, faceParmPt, u1, v1, u2, v2, faceNorm, principalRadii)

'is normal facing away from axis (boss) or is normal facing toward axis (hole)?
'create vector from axis to surface normal point
Dim bossVec(2) As Double
bossVec(0) = faceParmPt(0) - axisPt(0)
bossVec(1) = faceParmPt(1) - axisPt(1)
bossVec(2) = faceParmPt(2) - axisPt(2)

Dim normAngle As Double
theUfSession.Vec3.AngleBetween(faceNorm, bossVec, axisDir, normAngle)

If normAngle > 0.1 Then
'hole face, surface normal points toward cylindrical face axis
Return True
Else
'boss face, surface normal points away from cylindrical face axis
Return False
End If

End Function

Function FaceFromExtrude(ByVal testFace As Face) As Boolean

'get feature that created the face
Dim faceFeat As Features.Feature
Dim faceFeatTags() As Tag = Nothing
theUfSession.Modl.AskFaceFeats(testFace.Tag, faceFeatTags)
For Each tempTag As Tag In faceFeatTags
faceFeat = Utilities.NXObjectManager.Get(faceFeatTags(0))
If TypeOf (faceFeat) Is Features.Extrude Then
Return True
End If
Next

Return False

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

In the above code i want to Sort the Holes based on Diameter and Depth. Could you please help me.

Ravikumar