9 Replies Latest reply on Oct 17, 2018 1:09 AM by Peter Pankras

    Balloon-change between item no. and props

    Niels Raahauge

      Hi

      I use two kind of balloon.

      1) item number with circle

      2) Custom property SAPMaterrial without circle.

      I want a macro to change between those to. Finding all the balloons  and change to SAPMaterial is working. 

      But I can't find out how to detect the Balloon type to get the chose, and ether how to get the item no. in the balloon.

      I found:  swDetailingNoteTextItemNumber 2  but can't figure out how to use it.

      Can somebody help, please. (I have comment out my best guess)

       

      '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

      '                BaloonType = swAnnotation.GetAttachedEntityTypes

                                  

      '              If BaloonType = 2 Then 'item number

                          Bool = Note.SetBalloon(0, 0)  'no circle

                          Bool = Note.SetBomBalloonText(4, "$PRPMODEL:" & Chr(34) & "SAPMaterial" & Chr(34), 1, "") 'SetBallonToSAPMaterial

      '               Else

      '                   Bool = Note.SetBalloon(1, 0)  'circle

      '                   Bool = Note.SetBomBalloonText(>>>itemnumber<<<<<

                  End If

                  Set Note = Note.GetNext

               Wend

               Set View = View.GetNextView

            Wend

         End If

      End If

       

      End Sub

        • Re: Balloon-change between item no. and props
          Nilesh Patel

          Try:

           

          Bool = Note.SetBomBalloonText(swDetailingNoteTextContent_e.swDetailingNoteTextItemNumber, "", swDetailingNoteTextContent_e.swDetailingNoteTextCustom, "")

          • Re: Balloon-change between item no. and props
            Peter Pankras

            Hi,

             

            Did you get this to work?

             

            I'm looking for something similar, however my knowledge of macro's is zero.

             

            What I need is to at least understand is how I can change the text in a balloon with a macro.

             

            We use inspection to create the ballooning, however we want to change the numbers with letter. 1 should be A, 2 should be B etc..

             

            I figured it's doable if you can write a macro or script that select all balloons, checks the text en then do a IF text = 1 change to A for example.

            Your macro seems to be a nice base for something like this.

              • Re: Balloon-change between item no. and props
                Niels Raahauge

                Hi Peter

                I think you ca use nNumberOfItems to catch an array with a,b,c,d ... place it where the property are in the code.

                Dim myarray As Variant
                myarray
                = Array("A", "B", "C")

                BR Niels

                 

                'IF drawing name XXXXXXXXXXXXXXXXXX0 then ballons with item number

                'IF drawing name XXXXXXXXXXXXXXXXXX1 then ballons with custprop SAPMaterial

                 

                Dim SwApp As SldWorks.SldWorks

                Dim Model As SldWorks.ModelDoc2

                Dim View As Object

                Dim Note As Object

                Dim Bool As Boolean

                Dim nNumberOfItems As Integer

                 

                Dim SAP_part As String

                Dim swConfigMgr As SldWorks.ConfigurationManager

                Dim swConfig As SldWorks.Configuration

                Dim swCustPropMgr As SldWorks.CustomPropertyManager

                 

                Sub main()

                 

                Set SwApp = Application.SldWorks

                Set Model = SwApp.ActiveDoc

                 

                Dim reesolvedValOut As String

                 

                If Model Is Nothing Then

                MB = MsgBox("No drawing loaded!", vbCritical)

                Exit Sub

                End

                End If

                 

                Set swCustPropMgr = Model.Extension.CustomPropertyManager("")

                swCustPropMgr.Get2 "SAPPart", SAP_part, reesolvedValOut

                 

                If Model.GetType <> 3 Then

                SwApp.SendMsgToUser "Current document is not a drawing."

                End

                End If

                 

                DocOrPrd = Right(Left(Model.GetTitle, InStrRev(Model.GetTitle, " Sheet") - 3), Len(Left(Model.GetTitle, InStrRev(Model.GetTitle, " Sheet") - 3)) - 18)

                 

                nNumberOfItems = 0

                 

                If Not Model Is Nothing Then

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

                      Set View = Model.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

                            nNumberOfItems = nNumberOfItems + 1

                                If DocOrPrd = 1 Then

                                    'Set to item number circle arround ballon

                                    Bool = Note.SetBalloon(0, 0)  ' no circle around balloon

                                    Bool = Note.SetBomBalloonText(swDetailingNoteTextContent_e.swDetailingNoteTextItemNumber, "", swDetailingNoteTextContent_e.swDetailingNoteTextCustom, "")

                                End If

                                If DocOrPrd = 0 Then

                                    'Set to SAPMaterial without circle arround ballon

                                    Bool = Note.SetBalloon(0, 0) ' circle around balloon

                                    Bool = Note.SetBomBalloonText(4, "$PRPMODEL:" & Chr(34) & "SAPMaterial" & Chr(34), 1, "")

                                End If

                            End If

                            Set Note = Note.GetNext

                         Wend

                         Set View = View.GetNextView

                      Wend

                   End If

                   Debug.Print nNumberOfItems

                   MsgBox (nNumberOfItems & "  ballons changed in views")

                End If

                End Sub