1 Reply Latest reply on Apr 28, 2016 9:51 AM by Deepak Gupta

    Inserting a balloon from macro off sheet crashes Solidworks

    Adam Carder

      I have a macro that gets the current revision property and inserts a formatted balloon on the page (EPDM revision control). The problem seems to exist when the user clicks off the sheet and then runs the macro. It cannot properly create the balloon, so Solidworks just crashes. I cannot seem to trap the error if the balloon is null. Is there a reliable way to select something on screen that overrides the user selection? Tried activating the sheet, but I could not get that to work. Using SW 2014 SP5

       

      Sub main()

       

      Dim swApp As Object

      Dim myNote As SldWorks.Note

      Dim swAnn As SldWorks.Annotation

      Dim swModel As SldWorks.ModelDoc2

      Dim revisionString As String

      Dim boolStatus As Boolean

       

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

       

      If (swModel.GetType = swDocumentTypes_e.swDocDRAWING) Then

       

          'Get revision prop

          revisionString = "A"

       

          'insert balloon

          Set myNote = swModel.InsertBOMBalloon2(2, 0, 0, revisionString, 0, "")

         

          If (myNote Is Nothing) Then

              Exit Sub

          End If

         

          'remove leader

          If myNote.IsBomBalloon() Then

              myNote.SetBalloon swBalloonStyle_e.swBS_Triangle, swBalloonFit_e.swBF_Tightest

              Set swAnn = myNote.GetAnnotation

              'boolStatus = swAnn.SetPosition(0, 0, 0)

              swAnn.SetLeader3 swLeaderStyle_e.swNO_LEADER, swLeaderSide_e.swLS_SMART, False, False, False, False

          End If

       

       

      End If

       

       

       

       

      End Sub