8 Replies Latest reply on May 11, 2015 6:31 AM by Yong Ning

    Set balloon uppertext and no leader in macro?

    Steve Soeder

      I am trying to write a macro to generate balloons with a single letter in them.

      I'm having no luck getting the UpperText property to set.

      I've tried setting it in the BalloonOptions object, prior to calling the InsertBomBalloon method and I've tried setting it after creating the balloon, using the SetBomBalloonText method.

      No matter what I do, the text is always just a question mark.

       

      The other problem I am having, is that the balloon is created with a leader.  I don't want a leader.  I just want a leaderless balloon.

      I'm not sure where to set this option; I don't see any type of leader property listed in the class members for INote or IBalloonOptions objects in the documentation. 

      Hoping someone else knows this.  I'm sure this exists somewhere, but I'm just not finding it.

       

      Here is where I'm at right now.

      Like I mentioned, I've also tried setting it in the balloon options prior to creation and I was still getting a question mark.  That's actually why I broke it out into separate create and modify operations. I would prefer to keep it one operation if possible - just set the text at creation and not have to modify it.

      Option Explicit
      
      Dim swApp As SldWorks.SldWorks
      Dim Part As SldWorks.ModelDoc2
      
      
      Sub mainedit()
          Dim myNote          As SldWorks.Note
          Dim myBalOpt        As SldWorks.BalloonOptions
          Dim myDocExt        As SldWorks.ModelDocExtension
          Dim strLetter       As String
          Dim blnRet          As Boolean
          
          Set swApp = Application.SldWorks
          Set Part = swApp.ActiveDoc
          
          Set myBalOpt = Part.Extension.CreateBalloonOptions()
              
          strLetter = "A"
          
              With myBalOpt
                  .Style = swBS_Circular
                  .Size = swBF_2Chars
                  .UpperTextContent = swBalloonTextCustom
                  .UpperText = """"  'have tried setting this to strLetter and even explicitly setting to "A", still gives me a question mark in balloon
                  .LowerTextContent = swBalloonTextCustom
                  .LowerText = """"
              End With
          
          
          Set myNote = Part.Extension.InsertBOMBalloon2(myBalOpt)
          blnRet = myNote.SetBomBalloonText(myBalOpt.UpperTextContent, strLetter, myBalOpt.LowerTextContent, """")
      
      End Sub
      
        • Re: Set balloon uppertext and no leader in macro?
          Keith Rice

          The following code worked fine for me after I selected a face or edge in a drawing view.

           

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swBalloonOptions As SldWorks.BalloonOptions
          
          Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swBalloonOptions = swModel.Extension.CreateBalloonOptions
              swBalloonOptions.UpperText = "A"
              swModel.Extension.InsertBOMBalloon2 swBalloonOptions
          End Sub
          

           

          To remove a leader you need to use IAnnotation::SetLeader3.

           

          Keith

          SolidWorks API Tutorials

            • Re: Set balloon uppertext and no leader in macro?
              Steve Soeder

              Thanks Kieth!
              I was unaware that you had to select an object to attach the balloon to first.

              That is kind of disappointing for what I wanted to do.

               

              I wish the API documentation included a "members of" and "belongs to" list for each object / property / method.

                • Re: Set balloon uppertext and no leader in macro?
                  Keith Rice

                  You can select an entity in a drawing view using IView::SelectEntity. You can get the visible entities in a view using IView::GetVisibleEntities2.

                   

                  A method or property can only be a member of one interface (stated in parentheses after the member), so that list would only ever have one item in it. If you are getting members confused, you can simply type in the member name in the Index tab in the local API Help. There you will see a list of all methods and properties that have that name:

                   

                  If I have answered your question correctly then I would appreciate it if you marked my answer as correct. Thanks.

                   

                  Keith

                  SolidWorks API Training

                    • Re: Set balloon uppertext and no leader in macro?
                      Steve Soeder

                      Thanks Keith, I've marked your answer correct.

                      I haven't had time to test it, but I'll take your word for it until I do

                       

                       

                      I was trying to create the notes on an empty sheet.  I don't want them attached to anything.

                      Again, the fact that it has to be attached to any entity is not in the documentation that I could see.

                       

                      What I meant about membership in the documentation is that objects aren't shown along with the methods and properties as belonging to higher level objects.

                       

                      For instance, I had no idea the INote object was a child of the IAnnotation object.

                      I don't see where that link is defined in the documentation at all.

                      Without your help, I would have no idea that to remove the leader of an INote object I have to do so by using a method from the IAnnotation object.

                      The only thing I found that might tip someone off to this is under the Interop.Sldworks Namespace interface the description for IAnnotation says

                      "Allows access to notes, weld symbols, datum tags, display dimensions, blocks, cosmetic threads, center marks, centerlines, and other annotation types."

                      I guess that kind of hints at it, but nowhere does it clearly say the INote object is also a member of the IAnnotation class.

                       

                      2015 SOLIDWORKS API Help - SolidWorks.Interop.sldworks Namespace

                      2015 SOLIDWORKS API Help - INote Interface Members

                      2015 SOLIDWORKS API Help - IAnnotation Interface Members

                        • Re: Set balloon uppertext and no leader in macro?
                          Keith Rice

                          The only thing I found that might tip someone off to this is under the Interop.Sldworks Namespace interface the description for IAnnotation says "Allows access to notes, weld symbols, datum tags, display dimensions, blocks, cosmetic threads, center marks, centerlines, and other annotation types."

                           

                          Yes, this is how I knew. I also knew that a balloon qualified as INote because I probably used ISelectionMgr::GetSelectedObjectTypeX at some point in the past on a balloon.

                           

                          You are right that the documentation is often-times vague or unclear. I email the documentation team regularly about improvements in this area.

                           

                          Keith

                          SolidWorks API Tutorials

                    • Re: Set balloon uppertext and no leader in macro?
                      Steve Soeder

                      Keith,

                       

                      I've tried your code, it sill doesn't work for me.

                      See attached video.

                       

                      One thing I noticed in your code, you don't specify the balloon UpperTextContent type as swBalloonTextCustom  - I assumed this was necessary in order to provide a custom text value, no?

                       

                       

                       

                      Either way, if you watch the video you can see what happens when I run your code or my own.  Mine does seem to be properly setting the UpperTextContent type - you can see when I click on the balloon in the UI it is set to "Text"  - however the UpperText property won't take a value no matter what I do it seems.

                       

                      If you do not get this same behavior, then I will report this to my VAR as a bug.  It may be environmental in some way (I sure hope not, those suck to troubleshoot!!!)

                    • Re: Set balloon uppertext and no leader in macro?
                      Steve Soeder

                      I got some help from the Solidworks API team.

                      The reason my original code didn't work is because the SetBomBalloonText argument for UpperTextStyle takes a different enum than does the BalloonOptions.UpperTextContent property.

                       

                      SetBomBalloon wants this enum for the UpperTextStyle and LowerTextStyle arguments: swDetailingNoteTextContent_e

                      BalloonOptions wants this enum for the UpperTextContent and LowerTextContent properties: swBalloonTextContent_e

                       

                      I'm waiting for an answer on why the UpperText value doesn't work in the BalloonOptions object, but I have got everything working and can finish up now.

                       

                      Thanks for all your help Kieth!

                       

                      Here is the updated code:

                      Sub mainedit()
                          Dim myNote          As SldWorks.Note
                          Dim myBalOpt        As SldWorks.BalloonOptions
                          Dim myDocExt        As SldWorks.ModelDocExtension
                          Dim strLetter      As String
                          Dim lngX            As Long
                          Dim blnRet          As Boolean
                      
                          Set swApp = Application.SldWorks
                          Set Part = swApp.ActiveDoc
                          Set myDocExt = Part.Extension
                      
                          Set myBalOpt = myDocExt.CreateBalloonOptions()
                              
                              
                          strLetter = "-"
                          
                              Do
                                      With myBalOpt
                                          .Style = swBS_Circular
                                          .Size = swBF_2Chars
                                          .UpperTextContent = swBalloonTextCustom
                                          .UpperText = """"
                                          .LowerTextContent = swBalloonTextCustom
                                          .LowerText = """"
                                      End With
                                  
                                  
                                  Set myNote = Part.Extension.InsertBOMBalloon2(myBalOpt)
                                  blnRet = myNote.SetBomBalloonText(myNote.GetBomBalloonTextStyle(True), strLetter, myNote.GetBomBalloonTextStyle(False), """")
                          
                                  strLetter = NextRevLetter(strLetter)
                                  
                              Loop Until strLetter Like "YYY"
                      End Sub
                      
                        • Re: Set balloon uppertext and no leader in macro?
                          Yong Ning

                          Private Sub ll4()

                             Dim swApp As SldWorks.SldWorks, swModel As ModelDoc2

                                Set swApp = Application.SldWorks

                                Set swModel = swApp.ActiveDoc

                             Dim swSelMgr As SelectionMgr

                                Set swSelMgr = swModel.SelectionManager

                             Dim SwPt As ISketchPoint, PtArr(2) As Double

                                Set SwPt = swSelMgr.GetSelectedObject5(1)

                                Set swEnt = SwPt

                                ''

                                With SwPt

                                   PtArr(0) = .X

                                   PtArr(1) = .Y

                                End With

                                ''

                             Dim SwMathUtil As MathUtility

                                Set SwMathUtil = swApp.GetMathUtility

                             Dim SwMathPt As IMathPoint

                                Set SwMathPt = SwMathUtil.CreatePoint(PtArr)

                             Dim SwDraw As DrawingDoc, SwView As View

                                Set SwDraw = swApp.ActivateDoc("a.SldDrw")

                             Dim swNote As INote, oScale

                                'Set swNote = swModel.InsertBOMBalloon2( _

                                              swBS_SplitCirc, swBF_Tightest, _

                                              swBalloonTextCustom, "Upper text", _

                                              swBalloonTextCustom, "Lower text")

                                ''

                                Set SwView = SwDraw.GetFirstView

                                Set SwView = SwView.GetNextView

                                Ss = SwView.Position

                                oScale = 1 / SwView.ScaleDecimal

                                ''

                             Dim SwViewXForm As IMathTransform

                                Set SwViewXForm = SwView.ModelToViewTransform

                             Dim SwViewPt As IMathPoint

                                Set SwViewPt = SwMathPt.MultiplyTransform(SwViewXForm)

                                With SwViewPt

                                  tmp = SwView.SelectEntity(swEnt, False)

                                  Set Pt = SwDraw.CreatePoint2(.ArrayData(0) * oScale, .ArrayData(1) * oScale, 0)

                                  tmp = swModel.Extension.SelectByID2("", "FACE", .ArrayData(0) * oScale, .ArrayData(1) * oScale, 0, True, 0, Nothing, 0)

                                  Set swNote = SwDraw.InsertStackedBalloon(1, 1, 1, "", 0, "")

                                  'xx = .ArrayData(0) * 1000

                                  'yy = .ArrayData(1) * 1000

                                End With

                                'Stop

                           

                           

                          End Sub