2 Replies Latest reply on Aug 3, 2017 11:12 AM by Yong Ning

    How to align many  note  with API?

    Yong Ning

      Align.jpg

      use AlignHorz

      follow code don't align many note

       

       

       

      Private Sub del()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = Application.SldWorks

             Set SwModel = SwApp.ActiveDoc

         Dim SwDraw As DrawingDoc

             Set SwDraw = SwModel

             Stop

             SwDraw.AlignHorz

            

      End Sub

        • Re: How to align many  note  with API?
          Manikandan Babu

          Hi Ning,

          Please try the below code to align the left of selected annotations.

           

          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swdraw As SldWorks.DrawingDoc

          Dim boolstatus As Boolean

           

          Sub main()

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swdraw = swmodel

          'Selecting the Annotations

          boolstatus = swmodel.Extension.SelectByID2("DetailItem414@Drawing View1", "NOTE", 0.30421635550002, 0.549356344075223, 0, True, 0, Nothing, 0)

          boolstatus = swmodel.Extension.SelectByID2("DetailItem416@Drawing View1", "NOTE", 0.321497407017431, 0.517398235104668, 0, True, 0, Nothing, 0)

          boolstatus = swmodel.Extension.SelectByID2("DetailItem417@Drawing View1", "NOTE", 0.321497407017431, 0.490411387529533, 0, True, 0, Nothing, 0)

          boolstatus = swmodel.Extension.SelectByID2("DetailItem415@Drawing View1", "NOTE", 0.278886595056691, 0.456559464694056, 0, True, 0, Nothing, 0)

          swmodel.Extension.RunCommand swCommands_AnnotationAlignLeft, "Align to left"

          End Sub

           

          Manikandan

            • Re: How to align many  note  with API?
              Yong Ning

              2010 SOLIDWORKS API Help - swCommands_e Enumeration  http://help.solidworks.com/2010/english/api/swcommands/solidworks.interop.swcommands~solidworks.interop.swcommands.swcommands_e.html?verRedirect=1

               

              Thank you tip

              key word= swCommands_AnnotationAlignLeft

               

              swCommands_AnnotationAlignLeft.jpg

               

              swCommands_AnnotationAlignLeft

              swCommands_AnnotationAlignRight

              swCommands_AlignTop

              swCommands_AlignBottom

               

              In Solidworks 2008, run follow code is true.

              Sub Main()

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                         Set SwApp = Application.SldWorks

                         Set SwModel = SwApp.ActiveDoc

                         SwModel.Extension.RunCommand swCommands_AnnotationAlignLeft, "Align to left"

              End Sub

               

              *************************************************************

               

               

               

              Private Sub del2()

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                      Set SwApp = Application.SldWorks

                      Set SwModel = SwApp.ActiveDoc

                  Dim vConf, SwConf As Configuration

                      vConf = SwModel.GetConfigurationNames

                  Dim SwFeat As Feature

                  Dim SwAnn As Annotation, SwNote As Note

                  Dim vPos, aPos

                  Dim xDist, yDist

                      xDist = -500

                      yDist = 500

                      For ii = 0 To UBound(vConf)

                          SwModel.ShowConfiguration2 vConf(ii)

                          Set SwConf = SwModel.GetActiveConfiguration

                          'Debug.Print SwConf.Name

                          'Set SwFeat = SwModel.FirstFeature

                          Set SwAnn = SwModel.GetFirstAnnotation

               

                          Do While Not SwAnn Is Nothing

                               Set SwNote = SwAnn.GetSpecificAnnotation

                               With SwNote

                                   If .GetText <> "?" Then

                                        'Debug.Print .GetName, .GetText, SwConf.Name

                                        vPos = SwAnn.GetPosition

                                        aPos = .GetAttachPos

                                        Xx = aPos(0) + xDist / 1000

                                        Yy = aPos(1) + yDist / 1000

                                        zz = vPos(2)

                                        SwAnn.SetPosition Xx, Yy, zz

                                        'Stop

                                   End If

                               End With

                               Set SwAnn = SwAnn.GetNext

                          Loop

                          'Stop

                      Next ii

              End Sub

               

               

              ''

              Private Sub del3()

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                      Set SwApp = Application.SldWorks

                      Set SwModel = SwApp.ActiveDoc

                  Dim vConf, SwConf As Configuration

                      vConf = SwModel.GetConfigurationNames

                  Dim SwFeat As Feature

                  Dim SwAnn As Annotation, SwNote As Note

                  Dim vPos, aPos

                  Dim xDist, yDist

                      xDist = -500

                      yDist = 500

                      xDist = -150

                      yDist = 150

                  

                          Set SwAnn = SwModel.GetFirstAnnotation

               

                          Do While Not SwAnn Is Nothing

                               Set SwNote = SwAnn.GetSpecificAnnotation

                               With SwNote

                                   If .GetText <> "?" Then

                                        'Debug.Print .GetName, .GetText, SwConf.Name

                                        vPos = SwAnn.GetPosition

                                        aPos = .GetAttachPos

                                        Xx = aPos(0) + xDist / 1000

                                        Yy = aPos(1) + yDist / 1000

                                        zz = vPos(2)

                                        SwAnn.SetPosition Xx, Yy, zz

                                        'Stop

                                   End If

                               End With

                               Set SwAnn = SwAnn.GetNext

                          Loop

              End Sub