Message 1 of 3
How to count specific hole features in an assembly environment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am using Inventor 2024.
The logic to check the number of hole features used in a part in an assembly environment is structured as follows
-----------------------------------------------------------------------------------------------------
Sub Main()
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim N As Integer = 0 'holes counter
For Each oOcc As ComponentOccurrence In oAsmDef.Occurrences.AllLeafOccurrences
If Not oOcc.Suppressed Then
If oOcc.DefinitionDocumentType = kPartDocumentObject Then
Dim oDef As PartComponentDefinition = oOcc.Definition
N += GetHolesQty(oDef)
End If
End If
Next
Beep
MsgBox ("The number of holes in the current part is: " & N)
End Sub
'''Calculates holes in the part document
'''Be careful: nested patterns are not analyzed !
Function GetHolesQty(ByVal oDef As PartComponentDefinition) As Integer
Dim N As Integer = 0 'counter
Dim oHoles As HoleFeatures = oDef.Features.HoleFeatures
For Each oH As HoleFeature In oHoles
If Not oH.Suppressed Then
N += oH.HoleCenterPoints.Count
End If
Next
'have we any rectangular patterns ?
Dim oRectPatterns As RectangularPatternFeatures
oRectPatterns = oDef.Features.RectangularPatternFeatures
For Each oRPF As RectangularPatternFeature In oRectPatterns
Dim m As Integer = 0
If Not oRPF.Suppressed Then
If (TypeOf oRPF.ParentFeatures.Item(1) Is HoleFeature) Then
Dim oH As HoleFeature = oRPF.ParentFeatures.Item(1)
If Not oH.Suppressed Then
For Each oFPE As FeaturePatternElement In oRPF.PatternElements
If Not oFPE.Suppressed Then m += 1
Next
End If
End If
N += m - 1
Else
N += m
End If
Next
'have we any circular patterns ?
Dim oCircPatterns As CircularPatternFeatures
oCircPatterns = oDef.Features.CircularPatternFeatures
For Each oCPF As CircularPatternFeature In oCircPatterns
Dim m As Integer = 0
If Not oCPF.Suppressed Then
If (TypeOf oCPF.ParentFeatures.Item(1) Is HoleFeature) Then
Dim oH As HoleFeature = oCPF.ParentFeatures.Item(1)
If Not oH.Suppressed Then
For Each oFPE As FeaturePatternElement In oCPF.PatternElements
If Not oFPE.Suppressed Then m += 1
Next
End If
End If
N += m - 1
Else
N += m
End If
Next
Return N
End Function
-------------------------------------------------------------------------------------------------------------
What I would like to ask is, is it possible to configure logic to identify the number of tabs used in an assembly, not all hole features, by type?
The message box is expressed as follows.
ex) 10 M3s, 2 M5s, etc.
I think it would be possible to configure the message box to display the type and number of holes by utilizing the part about HoleType.
Is it possible to configure it with logic?