add drawing annotation

Hi,

I'm trying to add on drawing this anotation on every thread (only thread)

Exemple de MEP

My code for selected all cercle but i'm trying to finish the add anotation

Option Explicit Dim swApp <span class="">As</span> SldWorks.SldWorks Dim swModel <span class="">As</span> SldWorks.ModelDoc2 Dim swDraw <span class="">As</span> SldWorks.DrawingDoc Dim swView <span class="">As</span> SldWorks.View Dim Comp <span class="">As</span> SldWorks.Component2 Dim vComps <span class="">As</span> Variant Dim vComp <span class="">As</span> Variant Dim vEdges <span class="">As</span> Variant Dim vEdge <span class="">As</span> Variant Dim swEdge <span class="">As</span> SldWorks.Edge Dim swCurve <span class="">As</span> SldWorks.Curve Dim swEntity <span class="">As</span> SldWorks.Entity Dim CurveParam <span class="">As</span> Variant Dim IsClosed <span class="">As</span> Boolean Dim Diameter <span class="">As</span> Double Dim boolstatus <span class="">As</span> Boolean Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swDraw = swModel Set swView = swDraw.ActiveDrawingView swModel.ClearSelection2 <span class="">True</span> vComps = swView.GetVisibleComponents <span class="">'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 '</span><span class="">If</span> Abs(Diameter - CurveParam(<span class="">6</span>) * <span class="">2</span> * <span class="">1000</span>) < <span class="">0.0001</span> Then Set swEntity = swEdge swEntity.Select4 <span class="">True</span>, Nothing <span class="">'ici le code pour cotation avec hole callout '</span>End <span class="">If</span> End <span class="">If</span> End <span class="">If</span> Next Next <span class="">'swModel.SetLineColor 255 swModel.ClearSelection2 True End Sub</span>

Thanks

Sébastien

SolidworksApi/macros
Answers 7
PB
PB 2021-04-08 Best Answer

Please see below for updated code

Option Explicit <br>Dim swApp As SldWorks.SldWorks <br>Dim swModel As SldWorks.ModelDoc2 <br>Dim swDraw As SldWorks.DrawingDoc <br>Dim swView As SldWorks.View <br>Dim Comp As SldWorks.Component2 <br>Dim vComps As Variant <br>Dim vComp As Variant <br>Dim vEdges As Variant <br>Dim vEdge As Variant <br>Dim swEdge As SldWorks.Edge <br>Dim swCurve As SldWorks.Curve <br>Dim swEntity As SldWorks.Entity <br>Dim CurveParam As Variant <br>Dim IsClosed As Boolean <br>Dim Diameter As Double <br>Dim boolstatus As Boolean <br>Sub main() <br>  Set swApp = Application.SldWorks <br>  Set swModel = swApp.ActiveDoc <br>  Set swDraw = swModel <br>  Set swView = swDraw.ActiveDrawingView <br>  swModel.ClearSelection2 True <br>  vComps = swView.GetVisibleComponents <br>  'Diameter = InputBox("Entrer le diamètre en mm") <br>  For Each vComp In vComps <br>    Set Comp = vComp <br>    vEdges = swView.GetVisibleEntities(Comp, swViewEntityType_e.swViewEntityType_Edge) <br>      For Each vEdge In vEdges <br>        Set swEdge = vEdge <br>        Set swCurve = swEdge.GetCurve <br>        If swCurve.IsCircle Then <br>           swCurve.GetEndParams Empty, Empty, IsClosed, Empty <br>           If IsClosed Then <br>            CurveParam = swCurve.CircleParams <br>            'If Abs(Diameter - CurveParam(6) * 2 * 1000) < 0.0001 Then Set swEntity = swEdge swEntity.Select4 True, Nothing <br>            'ici le code pour cotation avec hole callout <br>            'End If <br>	   End If <br>	 End If <br>       Next <br>   Next <br>  'swModel.SetLineColor 255 <br>  swModel.ClearSelection2 True <br>End Sub<span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>

I don't get the question but I thought this would be helpful to someone who can give an answer.

Thanks & Regards

Prashant Baher

JC
JC 2021-04-08

If you change hole callouts, you will need an addin to maintain them as solidworks will constantly overwrite the call-out text you provide. Trust me. It's not something you want to battle against.

When a view is clicked solidworks will update the call-out, when a callout is moved, sometimes solidworks will overwrite your callout. 

It's not so fun to deal with. 

PB
PB 2021-04-08

Hi,

I am sorry I don't understand "Balise" !!!
But I can show you how I paste code and format them in this forum.

Please see below GIF file.

Option Explicit <br>Dim swApp As SldWorks.SldWorks <br><br>Dim Diameter As Double <br>Dim boolstatus As Boolean <br>Sub main() <br><br>End Sub<span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>

This is just demo code.

I hope this will help you.

Thanks & Regards

Prashant Baher

comment imagecomment image
SD
SD 2021-04-08

That's works but i dont want this:

"Trou Taraudé M10" but only "M10"

Is this possible without modifying the file: calloutformat.txt

for my part I tried this code but impossible to limit the anotation only to the treads:

Dim Annotations As Variant
Annotations = SwDraw.InsertModelAnnotations3(0, swInsertAnnotation_e.swInsertholeCallout, True, False, False, False)

SD
SD 2021-04-08

I try this monday, today it's not possible Thanks

SD
SD 2021-04-08

How to Ctr+V with balise for code please?

ST
ST 2021-04-08

Instead of finding circular edges in the model, you need to find Cosmetic Threads in the drawing view.

Try this:


    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
    End If