6 Replies Latest reply on Apr 9, 2017 7:11 AM by Peter Brinkhuis

    VBA to Change Balloon Leader Type

    Cad Admin

      I currently run a macro that selects all the balloons on a drawing sheet & formats them using

       

      Set myNote = swModel.Extension.EditBalloonProperties2(swBalloonStyle_e.swBS_Circular, swBalloonFit_e.swBF_3Chars, swBalloonTextContent_e.swBalloonTextItemNumber, "", 0, "", 0.01016, False, 1, "X", 0.0035)

       

      However this doesn't control the "leader style"...  i found SetLeader3, does it apply to "balloons" or just note/annotations?  If so i would want to set all leaders to swStraight.

        • Re: VBA to Change Balloon Leader Type
          Keith Rice

          Balloons are considered a note (and therefore a type of annotation) in SolidWorks.

           

          Keith

          SolidWorks API Training and Services

          • Re: VBA to Change Balloon Leader Type
            Cad Admin

            So in my code, i need every balloon leader changed i can alter under Set myNote, similarly too the edit balloon code?  Sorry i see Daft today

              • Re: VBA to Change Balloon Leader Type
                Raghvendra Bhargava

                Try this:

                 

                Dim ann As Annotation

                Dim swNote As Note

                 

                Set swNote = Part.SelectionManager.GetSelectedObject6(1, -1)

                Set ann = swNote.GetAnnotation

                Dim longError As Long

                longError = ann.SetLeader3(swLeaderStyle_e.swSTRAIGHT, 0, False, False, False, False)

                  • Re: VBA to Change Balloon Leader Type
                    Cad Admin

                    I'm Getting a type mismatch...on Set swNote = swModel.SelectionManager.GetSelectedObject6(1, -1)

                     

                    Code is below

                     

                    Option Explicit

                     

                    Dim swApp           As SldWorks.SldWorks

                    Dim swModel         As SldWorks.ModelDoc2

                    Dim Part            As ModelDoc2

                    Dim swDraw          As SldWorks.DrawingDoc

                    Dim vSheetName      As Variant

                    Dim i               As Integer

                    Dim bRet            As Boolean

                    Dim boolStatus      As Boolean

                    Dim longstatus      As Long, longwarnings As Long

                    Dim myNote          As Object

                    Dim ann             As Annotation

                    Dim swNote          As Note

                     

                    Sub main()

                     

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swDraw = swModel

                     

                    ' Get the sheets in the drawing document

                    vSheetName = swDraw.GetSheetNames

                     

                    ' Traverse the drawing sheets

                    For i = 0 To UBound(vSheetName)

                       bRet = swDraw.ActivateSheet(vSheetName(i))

                     

                    ' Fix balloon format

                    boolStatus = swModel.Extension.SelectByID2("Sheet1", "SHEET", 0.447009512681891, 0.454793066248622, 0, False, 0, Nothing, 0)

                    boolStatus = swModel.Extension.SketchBoxSelect("0.0", "0.0", "0.000000", "100000", "100000", "0.000000")

                    Set myNote = swModel.Extension.EditBalloonProperties2(swBalloonStyle_e.swBS_Circular, swBalloonFit_e.swBF_3Chars, swBalloonTextContent_e.swBalloonTextItemNumber, "", 0, "", 0.01016, False, 1, "X", 0.0035)

                     

                    ' Fix balloon leader format

                    Set swNote = swModel.SelectionManager.GetSelectedObject6(1, -1)

                    Set ann = swNote.GetAnnotation

                    Dim longError As Long

                    longError = ann.SetLeader3(swLeaderStyle_e.swSTRAIGHT, 0, False, False, False, False)

                     

                    swModel.ClearSelection

                     

                    Next i

                     

                    End Sub

                      • Re: VBA to Change Balloon Leader Type
                        Peter Brinkhuis

                        The issue here is that you select everything first and then assume that every selected item is a note. In my case it worked when I used the second selected item, which means the first item is something else.

                         

                        I think you should try either:

                        1. To find a better way of selecting all balloons
                        2. To check the type of the selected item(s)
                          • Re: VBA to Change Balloon Leader Type
                            Peter Brinkhuis

                            I tried to find all balloons and change their leader style. I selected all notes programmatically instead of trying to imitate the user's actions. Because I had trouble identifying balloons from revision symbols, I added the check with the balloon size. You might need other checks to make sure you only change balloon styles.

                             

                            Option Explicit

                             

                            Sub main()

                             

                                Dim swApp           As SldWorks.SldWorks

                                Dim swModel         As ModelDoc2

                                Dim swDraw          As DrawingDoc

                                Dim swView          As View

                                Dim swNote          As Note

                                Dim swAnn           As Annotation

                              

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                                Set swDraw = swModel

                              

                                Set swView = swDraw.GetFirstView

                                Set swView = swView.GetNextView

                              

                                While Not swView Is Nothing

                                    Debug.Print "---------"

                                    Debug.Print swView.Name

                                    Set swNote = swView.GetFirstNote

                              

                                    While Not swNote Is Nothing

                              

                                        Debug.Print "Note name: " & swNote.GetName

                                        Debug.Print "Balloon size: " & swNote.GetBalloonSize

                                      

                                        If swNote.GetBalloonSize > 0 Then

                                            Set swAnn = swNote.GetAnnotation

                                            Debug.Print "Setting balloon leader"

                                            'swann.SetLeader3 add settings here

                                        End If

                              

                                        Set swNote = swNote.GetNext

                                    Wend

                                  

                                    Set swView = swView.GetNextView

                                Wend

                            End Sub