Show ThreadType of Tap Hole and Taper Tap Hole.

Show ThreadType of Tap Hole and Taper Tap Hole.

tim11_manhhieu
Advocate Advocate
227 Views
2 Replies
Message 1 of 3

Show ThreadType of Tap Hole and Taper Tap Hole.

tim11_manhhieu
Advocate
Advocate

I want to display the Thread Type names of each Hole Feature via message box to check the hole profile.

For example: Hole1: ISO Metric profile, Hole3: NPT for PVC...,  Hole5: JIS Pipe Threads

iLogic or VBA are both fine.

 

tim11_manhhieu_0-1749178400552.png

 

0 Likes
Accepted solutions (1)
228 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

You can try something like this:

 

Dim doc As PartDocument = ThisDoc.Document

Dim features = doc.ComponentDefinition.Features

Dim f As New Dictionary(Of String, List(Of String))

For Each feature As HoleFeature In features.HoleFeatures

    If (Feature.HoleType <> HoleTypeEnum.kDrilledHole) Then Continue For

    Dim info = Feature.TapInfo
    Dim threadType As String

    If (TypeOf info Is HoleTapInfo) Then
        Dim tapInfo As HoleTapInfo = info
        threadType = tapInfo.ThreadType
    End If

    If (TypeOf info Is TaperedThreadInfo) Then
        Dim tapInfo As TaperedThreadInfo = info
        threadType = tapInfo.ThreadType
    End If

    If (f.ContainsKey(threadType)) Then
        f.Item(threadType).Add(Feature.Name)
    Else
        Dim names As New List(Of String)
        names.Add(Feature.Name)
        f.Add(threadType, names)
    End If
Next

Dim msg = String.Empty
For Each kv As KeyValuePair(Of String, List(Of String)) In f
    msg += $"{kv.Key}: {String.Join(", ", kv.Value)}" + System.Environment.NewLine
Next
MsgBox(msg)

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

tim11_manhhieu
Advocate
Advocate

Thank you for the help.

I ran your code on my computer and it gave me an error at the line msg+=... (Character is not valid).

The code worked fine when I changed it to msg += kv.Key & ": " & String.Join(", ", kv.Value) & System.Environment.NewLine

 

tim11_manhhieu_0-1749428146721.png

 

 

0 Likes