API solidworks Hole Callout

Hello

I'm developing a macro that makes our drawings for laser cutting from the workpiece.

For the most part it is functional but I still have a part to finalize concerning the rating of the taps.

I would like my macro to select the circles of my view 1 by 1 and then if it is a tap (and only if it is a tap) the side in this form M10 or if not non-standard M10x1 (see example below)

For the moment I manage thanks to a macro (retrieved here) to select the circles, but I get stuck on the quote part, I have recovered one or 2 codes on hole callout, but many don't even work in the recovered version.

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim Comp As SldWorks.Component2
Dim vComps As Variant
Dim vComp As Variant
Dim vEdges As Variant
Dim vEdge As Variant
Dim swEdge As SldWorks.Edge
Dim swCurve As SldWorks.Curve
Dim swEntity As SldWorks.Entity
Dim CurveParam As Variant
Dim IsClosed As Boolean
Dim Diameter As Double
Dim boolstatus As Boolean

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swView = swDraw.ActiveDrawingView
swModel.ClearSelection2 True
vComps = swView.GetVisibleComponents
'Diameter = InputBox("Entrer le diamètre en mm")
For Each vComp In vComps
    Set Comp = vComp
    vEdges = swView.GetVisibleEntities(Comp, swViewEntityType_e.swViewEntityType_Edge)
    For Each vEdge In vEdges
        Set swEdge = vEdge
        Set swCurve = swEdge.GetCurve
        If swCurve.IsCircle Then
            swCurve.GetEndParams Empty, Empty, IsClosed, Empty
            If IsClosed Then
                CurveParam = swCurve.CircleParams
                'If Abs(Diameter - CurveParam(6) * 2 * 1000) < 0.0001 Then
                    Set swEntity = swEdge
                    swEntity.Select4 True, Nothing
                    'ici le code pour cotation avec hole callout
                'End If
            End If
        End If
    Next
Next
'swModel.SetLineColor 255
swModel.ClearSelection2 True
End Sub

Exemple de MEP

1 Like

Hello

I'm back for my partially solved problem, I can now put the annotation by another method on the other hand I don't want the tapped hole information, I would only like the M10x1 or M10 information. If anyone has an idea on the subject. Thank you.

Dim vThreads As Variant
    Dim vThread As Variant
    Dim swThread As CThread
    Dim swAnn As Annotation
    Dim swDrawingComp As DrawingComponent
    
    vThreads = swView.GetCThreads
    If Not IsEmpty(vThreads) Then
        For Each vThread In vThreads
            Set swThread = vThread
            Set swAnn = swThread.GetAnnotation
            Set swDrawingComp = swView.RootDrawingComponent
            boolstatus = swModel.Extension.SelectByID2(swAnn.GetName & "@" & swDrawingComp.Name & "@" & swView.Name, "CTHREAD", 0, 0, 0, False, 0, Nothing, 0)
            swDraw.InsertThreadCallout
        Next