Number of holes of the hole package

On below code (basic on NX NXJournaling http://nxjournaling.com/content/extracting-pattern-features ) I added information about number of hole / thread hole ... general about number of feature holes. Journal working very well. Additionally I would like to add information about the quantity of repeated holes. For example I have 2 pcs. simple hole features where hole diameter is 6 and 2 pcs. simple hole diameter where simple hole diameter is 8. By each simple hole features I made few holes.
Below journal show me something like this:

general hole form: Simple
hole diameter: 6
hole depth: 20
General number of holes: 2

general hole form: Simple
hole diameter: 8
hole depth: 20
General number of holes: 9

general hole form: Simple
hole diameter: 8
hole depth: 30
General number of holes: 5

general hole form: Simple
hole diameter: 6
hole depth: 10
General number of holes: 5

On the end I would like to know how many hole diameter 6 and 8 is. How to add this information?

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim featArray() As Feature = workPart.Features.GetFeatures()
Dim i As Integer = 0
Dim SimpleHole() As Integer

For Each myFeature As Feature In featArray
If myFeature.FeatureType = "HOLE PACKAGE" Then
Dim holeFeature As HolePackage = myFeature
Dim holeDir() As Vector3d
holeFeature.GetDirections(holeDir)

Dim holeBuilder As HolePackageBuilder
holeBuilder = workPart.Features.CreateHolePackageBuilder(holeFeature)

Dim holeSection As Section = holeBuilder.HolePosition
Dim holeSectionData() As SectionData
holeSection.GetSectionData(holeSectionData)
Dim holeSectionElements() As SectionElementData
holeSectionData(0).GetSectionElementsData(holeSectionElements)
For Each temp As SectionElementData In holeSectionElements
Dim secElement As DisplayableObject
Dim stConnector As DisplayableObject
Dim stPoint As Point3d
Dim endConnector As DisplayableObject
Dim endPoint As Point3d
temp.GetSectionElementData1(secElement, stConnector, stPoint, endConnector, endPoint)
lw.WriteLine("start point: " & stPoint.ToString)
Next

lw.WriteLine("hole type: " & holeBuilder.Type.ToString)

If holeBuilder.Type = HolePackageBuilder.Types.GeneralHole Then
lw.WriteLine("general hole form: " & holeBuilder.GeneralHoleForm.ToString)
If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Simple Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralSimpleHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralSimpleHoleDepth.Value.ToString)
end if

lw.WriteLine("General number of holes: " & holeDir.Length.ToString)

End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Counterbored Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCounterboreHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.GeneralCounterboreHoleDepth.Value.ToString)
lw.WriteLine("counterbore diameter: " & holeBuilder.GeneralCounterboreDiameter.Value.ToString)
if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("counterbore depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("counterbore depth: " & holeBuilder.GeneralCounterboreDepth.Value.ToString)
end if
lw.WriteLine("Counterbored number of holes: " & holeDir.Length.ToString)
End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Countersink Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCountersinkHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralCountersinkHoleDepth.Value.ToString)
end if

lw.WriteLine("countersink diameter: " & holeBuilder.GeneralCountersinkDiameter.Value.ToString)
lw.WriteLine("countersink angle: " & holeBuilder.GeneralCountersinkAngle.Value.ToString)
lw.WriteLine("Countersink number of holes: " & holeDir.Length.ToString)
End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Tapered Then
'code for tapered holes
lw.WriteLine("hole diameter: " & holeBuilder.GeneralTaperedHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralTaperedHoleDepth.Value.ToString)
end if

lw.WriteLine("taper angle: " & holeBuilder.GeneralTaperAngle.Value.ToString)
lw.WriteLine("Tapered number of holes: " & holeDir.Length.ToString)
End If

End If

If holeBuilder.Type = HolePackageBuilder.Types.DrillSizeHole Then
lw.WriteLine("drill size: " & holeBuilder.DrillSize)
lw.WriteLine("drill size hole diameter: " & holeBuilder.DrillSizeHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("drill hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("drill hole depth: " & holeBuilder.DrillSizeHoleDepth.Value.ToString)
end if
lw.WriteLine("Drill Size number of holes: " & holeDir.Length.ToString)
End If

If holeBuilder.Type = HolePackageBuilder.Types.ScrewClearanceHole Then
lw.WriteLine("screw size: " & holeBuilder.ScrewSize)
lw.WriteLine("hole diameter: " & holeBuilder.ScrewClearanceHoleDiameter.Value.ToString)
lw.WriteLine("hole depth: " & holeBuilder.ScrewClearanceHoleDepth.Value.ToString)
lw.WriteLine("Screw Clearance number of holes: " & holeDir.Length.ToString)
End If

If holeBuilder.Type = HolePackageBuilder.Types.ThreadedHole Then
lw.WriteLine("thread size: " & holeBuilder.ThreadSize)

if holeBuilder.ThreadLengthOption = holeBuilder.ThreadLengthOption.Full then
lw.WriteLine("thread depth: " & holeBuilder.ThreadLengthOption.ToString)
else
lw.WriteLine("thread depth: " & holeBuilder.ThreadDepth.Value.ToString)
end if

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.ThreadedHoleDepth.Value.ToString)
end if
lw.WriteLine("Thread number of holes: " & holeDir.Length.ToString)
End If

If holeBuilder.Type = HolePackageBuilder.Types.HoleSeries Then
lw.WriteLine("hole series")
End If

lw.WriteLine("")

End If

Next
lw.Close()

End Sub

End Module

I use NX10.

Thanks
Marcin

I'd suggest using some variables to keep a 'running total' of each size of hole while the code runs. I think that a dictionary object would be a clean solution to this problem. When you find a hole of a specific size, check the dictionary to see if there is an entry for that size. If there is no entry, create one for that size and the number of holes that you found. If there is an entry, add the number of holes found to the previous entry. At the end of the journal, you will have the total number of each size of hole found.

Below is a quick code example of using a dictionary to keep a running total. The code is meant to illustrate how to use a dictionary object; it does not query the model for hole features, rather it uses random numbers to "generate" some information to keep track of. It shows how to add/update the information as it is found.

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

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim r As Random = New Random()

Dim holeQuantities As New Dictionary(Of Integer, Double)

For i As Integer = 0 To 16

'generate a random "hole series"
Dim holeDia As Integer = r.Next(10, 16)
Dim holeQty As Integer = r.Next(1, 6)

lw.WriteLine("hole diameter: " & holeDia.ToString & " quantity: " & holeQty.ToString)

'add hole series to dictionary
If holeQuantities.ContainsKey(holeDia) Then
'this hole size exists in the dictionary, add the new quantity to the existing quantity
holeQuantities.Item(holeDia) = holeQuantities.Item(holeDia) + holeQty

Else
'this hole does not exist in the dictionary yet
holeQuantities.Add(holeDia, holeQty)

End If

Next

lw.WriteLine("")
lw.WriteLine("totals")

For Each kvp As KeyValuePair(Of Integer, Double) In holeQuantities

lw.WriteLine("hole diameter: " & kvp.Key.ToString & " total: " & kvp.Value.ToString)

Next

lw.Close()

End Sub

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