How to determine whether hole/thread callout is placed on major or minor diameter

How to determine whether hole/thread callout is placed on major or minor diameter

Anonymous
Not applicable
751 Views
1 Reply
Message 1 of 2

How to determine whether hole/thread callout is placed on major or minor diameter

Anonymous
Not applicable

Hello,

 

I've been wracking my brain trying to figure out how to leverage the API to figure out whether a hole/thread callout is placed on the major or minor diameter (starting from the threadInfos enumerator). At this point I can't remember everything I've tried or could think of trying, so I'm not going to get into any details because that would be more hassle than it's worth.

 

Basically my company requires, as a matter of style, that hole/thread callouts be placed on the major diameter. What I'm trying to do is flash a warning for any that aren't (when running a different script that modifies some information in the callout). If there's a way to automatically reposition it from the minor diameter, that would be even better.

 

Here is the script for context, and I've attached a test .ipt & .dwg (Inv 2022):

Public Sub Main()
    Dim invDWG As Document

    Dim i As Integer
    Dim invHoleThreadNote As Object
    Dim threadGeometry As Object
    Dim threadInfo As ThreadInfo
    Dim badlyPlacedCount As Integer

    Dim pitchMax As String
    Dim pitchMin As String
    Dim diaMax As String
    Dim diaMin As String

    Dim formattedText As String

    invDWG = ThisApplication.ActiveDocument


    For i = 1 To invDWG.ActiveSheet.DrawingNotes.HoleThreadNotes.Count
        Do
        'Filet externe ou interne
        invHoleThreadNote = invDWG.ActiveSheet.DrawingNotes.HoleThreadNotes(i)

        If Err.Number > 0 Then
            Err.Clear
        End If
        On Error GoTo NonexistentThreadInfos
        Select Case invHoleThreadNote.Edge.Type
        Case Is = "117473792" ' axial/DrawingCurve obj
            geom = invHoleThreadNote.Edge
            ' test whether major diameter is selected
        Case Is = "117474048" ' profile/'Edge' obj
            geom = invHoleThreadNote.Edge.Geometry
        Case Else
            ' to fail silently when the object shouldn't have thread info, or should but API access is unclear
            NonexistentThreadInfos:
            Resume NextCallout
            NextCallout:
            Exit Do
        End Select

        threadInfo = geom.ModelGeometry.ThreadInfos(1)

        pitchMax = FormatNumberAlias(threadInfo.PitchDiameterMax)
        pitchMin = FormatNumberAlias(threadInfo.PitchDiameterMin)

        'Filet externe
        If Not threadInfo.Internal Then
            diaMax = FormatNumberAlias(threadInfo.MajorDiameterMax)
            diaMin = FormatNumberAlias(threadInfo.MajorDiameterMin)

            formattedText = "MAJOR: " & diaMax & "/" & diaMin & vbCrLf & _
                            "PITCH: " & pitchMax & "/" & pitchMin

        'Filet interne
        Else
            diaMax = FormatNumberAlias(threadInfo.MinorDiameterMax)
            diaMin = FormatNumberAlias(threadInfo.MinorDiameterMin)

            formattedText = "MINOR: " & diaMin & "/" & diaMax & vbCrLf & _
                            "PITCH: " & pitchMin & "/" & pitchMax
        End If

        invHoleThreadNote.Text.formattedText = invHoleThreadNote.Text.formattedText & vbCrLf & formattedText

        'If geometry.ModelGeometry.GeometryType = kCircleCurve AND (threadInfo.Internal AND  OR NOT threadInfo.Internal AND ) Then
        '    badlyPlacedCount = badlyPlacedCount + 1
        'End If

        Loop While False
    Next i

    If badlyPlacedCount > 0 Then
        'MsgBox("Veuillez-vous assurer que touts les notes de filetage sont placés sur le diamètre principal du filetage. /" & vbCrLf & _
        '"Please ensure all thread callouts are placed on the thread's major diameter" & vbCrLf & _
        'vbCrLf & _
        '"Notes égarés / Callouts misplaced: " & badlyPlacedCount)
    End If


End Sub

Function FormatNumberAlias(value As String) As String
    Return FormatNumber(value, 4, -1)
End Function

 

Thanks

0 Likes
Reply (1)
Message 2 of 2

Michael.Navara
Advisor
Advisor

I don't know if it helps, but you can check the layer of attached drawing curve segment. It should be in layer "Visible". Some of the HoleNotes (on the right side of drawing) are attached to the segment in layer "Hidden Narrow".

MichaelNavara_0-1654235564904.png

It is not exact check, but you can use it as first approach.

 

If you can, you can create new layer for thread geometries and assign it to the thread geometries in ObjectDefaults in StylesManager. Later on you have better chance to determine, if the HoleNote is attached to bad curve segment.

 

Sometimes you can get the feature which creates this drawing curve. But there is  more then one way how to achieve this for different HoleNotes

MichaelNavara_1-1654236128058.png

 

 

0 Likes