2 Replies Latest reply on Jul 29, 2017 6:54 AM by Yong Ning

    How to  traverse sketchpoint with foreach in next method?

    Yong Ning

      Now use mathod → Ss = SwSk.GetSketchPoints

       

      Function DelSkPt(SwModel As ModelDoc2, SwSk As Sketch)

           Dim Ss

           Dim SkPt As SketchPoint

               ''

               Ss = SwSk.GetSketchPoints

               If IsEmpty(Ss) Then

                   Exit Function

               End If

               For ii = 0 To UBound(Ss)

                   Set SkPt = Ss(ii)

                   SkPt.Select True

               Next ii

               SwModel.EditDelete

      End Function

       

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

       

      Help me.

      Traverse SketchPoint → Foreach ... in .. next mehtod

        • Re: How to  traverse sketchpoint with foreach in next method?
          Ivana Kolin

          Function DelSkPt(SwModel As ModelDoc2, SwSk As Sketch)

               Dim Ss as variant

               Dim s as variant

               Dim SkPt As SketchPoint

                   ''

                   Ss = SwSk.GetSketchPoints

                   If IsEmpty(Ss) Then

                       Exit Function

                   End If

                   For each s in Ss

                       Set SkPt = s

                       SkPt.Select True

                   Next

                   SwModel.EditDelete

          End Function

            • Re: How to  traverse sketchpoint with foreach in next method?
              Yong Ning

              Thank you.Solution of two code is the same

               

              change code,

               

              Function DelSkPt(SwModel As ModelDoc2, SwSk As Sketch)

                   Dim Ss

                   Dim SkPt As SketchPoint

                       ''

                       If IsEmpty(SwSk.GetSketchPoints) Then

                           Exit Function

                       End If

                       For Each Ss In SwSk.GetSketchPoints

                           Set SkPt = Ss

                           SkPt.Select True

                       Next

                       SwModel.EditDelete

              End Function

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

              '''

              Function DelSkPt(SwModel As ModelDoc2, SwSk As Sketch)

                   Dim Ss

                   Dim SkPt As SketchPoint

                       ''

                       If IsEmpty(SwSk.GetSketchPoints) Then

                           Exit Function

                       End If

                       For Each Ss In SwSk.GetSketchPoints

                           Set SkPt = Ss

                           SkPt.Select True

                       Next

                       SwModel.EditDelete

              End Function

              Function CreatePt(SwModel As ModelDoc2, SwView As View, Pt)

                   Set CreatePt = SwModel.CreatePoint2( _

                        Pt(0) / SwView.ScaleDecimal, Pt(1) / SwView.ScaleDecimal, 0)

              End Function

              ''

               

               

               

               

              Private Sub del()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

                 Dim SwMathUtil As MathUtility

                     Set SwMathUtil = SwApp.GetMathUtility

                 Dim SwDraw As DrawingDoc

                     Set SwDraw = SwModel

                 Dim SwView As View, SwNote As Note

                     Set SwView = SwDraw.GetFirstView

                     DelSkPt SwModel, SwView.GetSketch

                     Set SwView = SwView.GetNextView

                     '

                 Dim vPt(2) As Double

                 Dim SkPt As SketchPoint

                 Dim MathPt As MathPoint

                 Dim Anns, SwAnn As Annotation, Ss, Xx, Yy

                     Anns = SwView.GetAnnotations

                     ''

                     For ii = 0 To UBound(Anns)

                         Set SwAnn = Anns(ii)

                         If SwAnn.GetType = 6 Then

                           Set SwNote = SwAnn.GetSpecificAnnotation

                           With SwNote

                              If .HasBalloon Then

                                 Set SkPt = CreatePt(SwModel, SwView, .GetAttachPos)

                                 SkPt.Select False

                              End If

                           End With

                         End If

                     Next ii

              End Sub