How to count specific hole features in an assembly environment

How to count specific hole features in an assembly environment

HYOSEOK-KIM
Participant Participant
138 Views
2 Replies
Message 1 of 3

How to count specific hole features in an assembly environment

HYOSEOK-KIM
Participant
Participant

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?

0 Likes
139 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

You could try something like this:

Public Class ThisRule

    Private holes As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)()

    Sub Main()
        Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
        Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition


        For Each oOcc As ComponentOccurrence In oAsmDef.Occurrences.AllLeafOccurrences
            If Not oOcc.Suppressed Then
                If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
                    Dim oDef As PartComponentDefinition = oOcc.Definition
                    GetHolesQty(oDef)
                End If
            End If
        Next

        Beep()

        Dim msg As String = ""
        For Each item As KeyValuePair(Of String, Integer) In holes

            Dim cell = String.Format("{0,-20}", item.Key)

            msg += String.Format("{0} : {1}{2}", cell, item.Value, System.Environment.NewLine)
        Next

        MsgBox(msg)
    End Sub


    '''Calculates holes in the part document
    '''Be careful: nested patterns are not analyzed !
    Sub GetHolesQty(ByVal oDef As PartComponentDefinition)

        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
                AddHoleInfo(oH, 1)
            End If
        Next

        'have we any rectangular patterns ?
        Dim oRectPatterns As RectangularPatternFeatures = oDef.Features.RectangularPatternFeatures

        For Each oRPF As RectangularPatternFeature In oRectPatterns
            If oRPF.Suppressed Then Continue For

            Dim holes = oRPF.ParentFeatures.Cast(Of PartFeature).
                Where(Function(f) Not f.Suppressed And TypeOf f Is HoleFeature).ToList()

            If (holes.Count = 0) Then Continue For

            Dim elements = oRPF.PatternElements.Cast(Of FeaturePatternElement).
                Where(Function(fpe) Not fpe.Suppressed).ToList()

            For Each hole As PartFeature In holes
                AddHoleInfo(hole, elements.Count - 1)
            Next
        Next

        'have we any circular patterns ?
        Dim oCircPatterns As CircularPatternFeatures
        oCircPatterns = oDef.Features.CircularPatternFeatures

        For Each oCPF As CircularPatternFeature In oCircPatterns
            If oCPF.Suppressed Then Continue For

            Dim holes = oCPF.ParentFeatures.Cast(Of PartFeature).
                Where(Function(f) Not f.Suppressed And TypeOf f Is HoleFeature).ToList()

            If (holes.Count = 0) Then Continue For

            Dim elements = oCPF.PatternElements.Cast(Of FeaturePatternElement).
                Where(Function(fpe) Not fpe.Suppressed).ToList()

            For Each hole As PartFeature In holes
                AddHoleInfo(hole, elements.Count - 1)
            Next

        Next
    End Sub


    Private Sub AddHoleInfo(hole As HoleFeature, numberOfHoles As Integer)

        Dim name As String = "Unknown"

        If (hole.Tapped) Then
            If (TypeOf hole.TapInfo Is HoleTapInfo) Then
                Dim info As HoleTapInfo = hole.TapInfo
                name = info.ThreadDesignation
            Else
                Dim info As TaperedThreadInfo = hole.TapInfo
                name = info.ThreadDesignation
            End If

        Else
            name = String.Format("Hole: {0}", hole.HoleDiameter.Expression)
        End If

        If holes.ContainsKey(name) Then
            holes(name) += numberOfHoles
        Else
            holes.Add(name, numberOfHoles)
        End If

    End Sub
End Class

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

HYOSEOK-KIM
Participant
Participant

Hello.

Thank you for your reply. There's something that needs to be corrected.

 

The logic reads the feature name "hole" and expresses it as a count.

The count I'm looking for is different information.

 

For example, assuming [Assembly 1] contains one [Part 1] and two [Part 2],

[Part 1] Hole1 feature contains two M6x1s, and Hole2 feature contains three M10x1s.
[Part 2] Hole1 feature contains one M6x1.

When executing the logic, I'd like the count results to be expressed as:
M6x1 = 4
M10x1 = 3
.

Concept:
- This is an assembly document.
- The total number of holes is ~.
- Of these, the number of holes with the "tap" attribute is ~.
- Of all the tap holes, the result would be ~ for "m1" and ~ for "m2"...

Is it possible to configure it with Inventor iLogic as above?

0 Likes