How to determine whether hole/thread callout is placed on major or minor diameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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