4 Replies Latest reply on Oct 17, 2018 1:50 AM by Peter Pankras

    macro to read balloon content in Drawing and change the note

    Peter Pankras

      Hi,

       

      I would like to create a macro that changes the Note in a balloon based on some sort of rule.

       

      My knowledge of VBA is very limited, and I would like to learn more based on this example.

       

      Here's the case.

       

      In a Drawing I have an X number of balloons.

      The Balloons are placed automaticly and numbered from 1 to n

       

      I need a script that does something like

       

      For the active drawing

           lookup the first balloon you find

           read the note in that balloon

           change that note by comparing it to maybe an array

           next balloon

       

      We need Letters in the balloons, so i want to replace 1 with A, 2 with B etc.

      My idea was to create an array for this

       

      something like

       

      Dim Bchar(1 To n) As String

       

      Bchar(1) = 'A'

      Bchar(2) = 'B'

      etc..

       

      I found a script that walks through all Dimensions in a drawing.

      How can I do the same but with balloons and then read the note and change it.

       

      Thanx

        • Re: macro to read balloon content in Drawing and change the note
          Nilesh Patel

          What do you do when you have more than 26 balloons in the drawing?

          • Re: macro to read balloon content in Drawing and change the note
            Peter Pankras

            based on The base code from Niels It should be something like

             

            'open a drawing with balloons

            'Macro to change all balloons to custom property: SAPMaterial

             

            Dim swApp As Object

            Dim Drw As Object

            Dim View As Object

            Dim Note As Object

            Dim Bool As Boolean

            'Dim swAnnotation As Annotation

            'Dim BaloonType As Integer

             

            Sub main()

             

            Set swApp = Application.SldWorks

            Set Drw = swApp.ActiveDoc

            If Not Drw Is Nothing Then

               If Drw.GetType = 3 Then            'Activedoc = Drawing?

                  Set View = Drw.GetFirstView     '= drawing sheet

                  Set View = View.GetNextView     '= first real view

                

                  While Not View Is Nothing       'loop through views

                     Set Note = View.GetFirstNote

                   

                     While Not Note Is Nothing    'loop through notes

                        If Note.IsBomBalloon Then

            '               swAnnotation = Note.GetAnnotation

             

            '               Get the Annotation in the Balloon

             

            '               Do some kind of change the Number to a Letter based on our custom array voodoo

                                       

                        End If

                        Set Note = Note.GetNext

                     Wend

                     Set View = View.GetNextView

                  Wend

               End If

            End If

             

            End Sub

             

            Since it's all kins of new to me..  Where can I find a good overview of all the calls I can make in a macro?

             

            For example..  look at the above Code...  you do a swAnnotation = Note.GetAnnotation

            so now you have the Annotation in the balloon..

             

            Where can I find how I can set the new annotaion in a balloon.

             

            Sorry if this is a basic question..  but I'm having a Hard time finding the right calls.

             

            Is there good API reference somewhere that can give me all I can do with a Balloon in Solidworks,

            I'm having difficult time finding any type of reference about it in the online Help