4 Replies Latest reply on Nov 12, 2018 3:11 AM by Adam Mircea

    Add additional Note inside a Block (positioning problem)

    Adam Mircea

      Hello all, i'm trying to add a note inside a block, where already exists a note.

       

      This is what i need :

      Start:

      1.PNG

      Result:

      2.PNG

       

      This is the code i'm testing :

       

      'editing the block

      boolstatus = swModel.Extension.SelectByID2(swFeature.Name & "-1", "SUBSKETCHINST", 0#, 0#, 0#, False, 0, Nothing, 0)

      swModel.SketchManager.EditSketchBlock

       

      'getting Note Position

      pos = swNote.IGetTextPoint2

       

      'inserting the others note

      Set myNote = swModel.InsertNote("<FONT style=B><border type=9 size=0 padding=0>11</border>")

      Set myAnnotation = myNote.GetAnnotation()

      boolstatus = myAnnotation.SetPosition(pos(0) + 0.05, pos(1), pos(2))

       

      Set myNote = swModel.InsertNote("<FONT style=B><border type=9 size=0 padding=0>123456789</border>")

      Set myAnnotation = myNote.GetAnnotation()

      boolstatus = myAnnotation.SetPosition(pos(0) + 0.05, pos(1) + 0.07, pos(2))

       

      The problem is... that i can't understand how the position is working.
      So when i'm trying to insert the new notes, the macro puts it completely away from my initial note. How can i fix this ? Have someone already seen this issue ?

       

      Thank you for reading,

      Adam.

        • Re: Add additional Note inside a Block (positioning problem)
          Fifi Riri

          Hello,

          The position of the note is given relative to the block.

          On top of that you need to consider the sheet scale and block transform.

          Try this:

           

          Option Explicit

          Dim swApp As SldWorks.SldWorks

          Dim swDraw As SldWorks.DrawingDoc

          Dim swBlockDef As SldWorks.SketchBlockDefinition

          Dim swBlockInst As SldWorks.SketchBlockInstance

          Dim swSheet As SldWorks.Sheet

          Dim swNote As SldWorks.Note

          Dim swAnn As SldWorks.Annotation

          Dim vNote As Variant

          Dim PosX As Double

          Dim PosY As Double

          Dim shtScale As Double

          Dim vXfm As Variant

          Dim TransfX As Double

          Dim TransfY As Double

          Dim boolstatus As Boolean

          Sub main()

          Set swApp = Application.SldWorks

          Set swDraw = swApp.ActiveDoc

          Set swSheet = swDraw.GetCurrentSheet

          shtScale = swSheet.GetProperties(3)

          swDraw.ClearSelection2 True

          boolstatus = swDraw.Extension.SelectByID2("Block1-1", "SUBSKETCHINST", 0, 0, 0, False, 0, Nothing, 0)

          Set swBlockInst = swDraw.SelectionManager.GetSelectedObject6(1, -1)

          swDraw.SketchManager.EditSketchBlock

          Set swBlockDef = swBlockInst.Definition

           

          Dim swXfm As MathTransform

          Set swXfm = swBlockInst.BlockToSketchTransform

          vXfm = swXfm.ArrayData

          TransfX = vXfm(9)

          TransfY = vXfm(10)

           

          vNote = swBlockDef.GetNotes

          If Not IsEmpty(vNote) Then

              Set swNote = vNote(0)

              If Not swNote Is Nothing Then

                  Set swAnn = swNote.GetAnnotation

                  PosX = swAnn.GetPosition(0)

                  PosY = swAnn.GetPosition(1)

              End If

          End If

           

          Set swNote = swDraw.InsertNote("<FONT style=B><border type=9 size=0 padding=0>11</border>")

          Set swAnn = swNote.GetAnnotation

          boolstatus = swAnn.SetPosition((TransfX + PosX + 0.05) / shtScale, (TransfY + PosY) / shtScale, 0)

           

          Set swNote = swDraw.InsertNote("<FONT style=B><border type=9 size=0 padding=0>123456789</border>")

          Set swAnn = swNote.GetAnnotation

          boolstatus = swAnn.SetPosition((TransfX + PosX + 0.05) / shtScale, (TransfY + PosY + 0.07) / shtScale, 0)

           

          swDraw.ClearSelection2 True

          swDraw.WindowRedraw

          swDraw.SketchManager.EndEditSketchBlock True

          End Sub

            • Re: Add additional Note inside a Block (positioning problem)
              Adam Mircea

              Thank you for your answer and for your time.

              I tried your code, unfortunly, even without the increment of + 0.05 and + 0.07, the annotations are placed far from the note, outside of the Drawing Sheet. I checked the scale and the block pos, seems correct. Maybe something wrong inside the sheet properties.

               

              I have attached the .SLDDRW that i'm working with... and asking you please to check it too.

               

              Thank you !!!

                • Re: Add additional Note inside a Block (positioning problem)
                  Fifi Riri

                  Try this

                   

                  Option Explicit

                  Dim swApp As SldWorks.SldWorks

                  Dim swDraw As SldWorks.DrawingDoc

                  Dim swBlockDef As SldWorks.SketchBlockDefinition

                  Dim swBlockInst As SldWorks.SketchBlockInstance

                  Dim swSheet As SldWorks.Sheet

                  Dim swNote As SldWorks.Note

                  Dim swAnn As SldWorks.Annotation

                  Dim swTextFormat As SldWorks.TextFormat

                  Dim vNote As Variant

                  Dim PosX As Double

                  Dim PosY As Double

                  Dim shtScale As Double

                  Dim vXfm As Variant

                  Dim TransfX As Double

                  Dim TransfY As Double

                  Dim boolstatus As Boolean

                  Sub main()

                  Set swApp = Application.SldWorks

                  Set swDraw = swApp.ActiveDoc

                  Set swSheet = swDraw.GetCurrentSheet

                  shtScale = swSheet.GetProperties(3)

                   

                  swDraw.ClearSelection2 True

                  boolstatus = swDraw.Extension.SelectByID2("PPDX02C-1", "SUBSKETCHINST", 0, 0, 0, False, 0, Nothing, 0)

                   

                  Set swBlockInst = swDraw.SelectionManager.GetSelectedObject6(1, -1)

                  swDraw.SketchManager.EditSketchBlock

                  Set swBlockDef = swBlockInst.Definition

                   

                  Dim swXfm As MathTransform

                  Set swXfm = swBlockInst.BlockToSketchTransform

                  vXfm = swXfm.ArrayData

                  TransfX = vXfm(9)

                  TransfY = vXfm(10)

                  'Debug.Print "Transf  " & TransfX & "   " & TransfY

                   

                  vNote = swBlockDef.GetNotes

                  If Not IsEmpty(vNote) Then

                      Set swNote = vNote(0)

                      Set swTextFormat = swNote.GetTextFormat

                      If Not swNote Is Nothing Then

                          Set swAnn = swNote.GetAnnotation

                          PosX = swAnn.GetPosition(0)

                          PosY = swAnn.GetPosition(1)

                      End If

                      'Debug.Print "pos   " & PosX & "   " & PosY

                  End If

                   

                  Set swNote = swDraw.InsertNote("123456789")

                  Set swAnn = swNote.GetAnnotation

                  boolstatus = swAnn.SetPosition((TransfX / shtScale + PosX + 0.0045), (TransfY / shtScale + PosY - 0.0038), 0)

                  boolstatus = swAnn.SetTextFormat(0, False, swTextFormat)

                   

                  Set swNote = swDraw.InsertNote("11")

                  Set swAnn = swNote.GetAnnotation

                  boolstatus = swAnn.SetPosition((TransfX / shtScale + PosX), (TransfY / shtScale + PosY - 0.0038), 0)

                  swTextFormat.Bold = True

                  boolstatus = swAnn.SetTextFormat(0, False, swTextFormat)

                  boolstatus = swNote.SetBalloon(swBalloonStyle_e.swBS_FlagPentagon, swBalloonFit_e.swBF_Tightest)

                   

                  swDraw.ClearSelection2 True

                  swDraw.WindowRedraw

                  swDraw.SketchManager.EndEditSketchBlock True

                  End Sub