3 Replies Latest reply on Jun 17, 2015 5:56 PM by Ivana Kolin

    How to get line name

    Yong Ning

      Record select line

      Sub main()

      Set SwApp = Application.SldWorks

      Set Part = SwApp.ActiveDoc

      Set SelMgr = Part.SelectionManager

      boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0.1267650291262, 0.1770293009709, 0, False, 0, Nothing, 0)

      End Sub

       

       

      select line name is "Line1"

       

      00.jpg

       

       

       

      follow code , don't debug.print  select line name?

       

      Private Sub ll()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

            Set SwApp = Application.SldWorks

            Set SwModel = SwApp.ActiveDoc

         Dim SwSelMgr As SelectionMgr, Ss

            Set SwSelMgr = SwModel.SelectionManager

         Dim SwLine As ISketchLine, SwSeg As ISketchSegment

            Set SwSeg = SwSelMgr.GetSelectedObject5(1)

            Debug.Print SwSeg.GetType ', SwSeg.GetID

            Ss = SwSeg.GetID

            Set SwLine = SwSelMgr.GetSelectedObject5(1)

       

      End Sub

        • Re: How to get line name
          Ivana Kolin

          I don't understand exactly what do you mean, but might is this what are you searching for?

           

          Debug.Print  Line" & SwSeg.GetID(0)

            • Re: How to get line name
              Yong Ning

              follow code result is

               

                  line[0]

                    start pt = (50, 50, 0) mm

                    end   pt = (100, 50, 0) mm

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

              Help , read line message → Save lines  text file.

              use

              read line text file.

                move line position.

              0.jpg

               

                  line[1]

                    start pt = (50, 100, 0) mm

                    end   pt = (100, 100, 0) mm

               

               

               

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

              Private Sub ll1()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwModel = SwApp.ActiveDoc

                 Dim SwDraw As DrawingDoc, SwView As View

                    Set SwDraw = SwModel

                    Set SwView = SwDraw.GetFirstView

                 Dim SwSketch As Sketch

                    Set SwSketch = SwView.GetSketch

                 Dim SwLine As SketchLine, vlines, ii

                    vlines = SwView.GetLines4(1)

                    ''

                    If Not IsEmpty(vlines) Then

                          ''

                          For ii = 0 To SwView.GetLineCount - 1 'lNumLines - 1

                              Debug.Print "    line[" & ii & "]"

                              Debug.Print "      start pt = (" & vlines(ii * 12 + 6) * 1000# & ", " & vlines(ii * 12 + 7) * 1000# & ", " & vlines(ii * 12 + 8) * 1000# & ") mm"

                              Debug.Print "      end   pt = (" & vlines(ii * 12 + 9) * 1000# & ", " & vlines(ii * 12 + 10) * 1000# & ", " & vlines(ii * 12 + 11) * 1000# & ") mm"

                          Next ii

                    End If

              End Sub

                • Re: How to get line name
                  Ivana Kolin
                  Option Explicit
                  Sub main()
                      Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
                      Set SwApp = Application.SldWorks
                      Set SwModel = SwApp.ActiveDoc
                      Dim swDraw As DrawingDoc, swView As View
                      Set swDraw = SwModel
                         
                      Set swView = swDraw.GetFirstView
                      
                      While Not swView Is Nothing
                          Debug.Print "    " & swView.GetName2 & " [" & swView.Type & "]"
                          
                          Dim SwSketch As Sketch
                         
                          Set SwSketch = swView.GetSketch
                          Dim SwLine As SketchLine, ii
                          
                          Dim vSketchSeg
                          vSketchSeg = SwSketch.GetSketchSegments
                          Dim swSkSegment As SldWorks.SketchSegment
                          Dim swPoint As SldWorks.SketchPoint
                           
                          If Not IsEmpty(vSketchSeg) Then
                              For ii = 0 To UBound(vSketchSeg)  'lNumLines - 1
                                  Set swSkSegment = vSketchSeg(ii)
                                  Debug.Print swSkSegment.GetID(0), swSkSegment.GetType
                                  Select Case swSkSegment.GetType
                                  Case swSketchLINE
                                      Set SwLine = swSkSegment
                                      If swSkSegment.GetID(0) = 0 Then
                                          Set swPoint = SwLine.GetStartPoint2
                                          swPoint.X = 50# / 1000
                                          swPoint.Y = 50# / 1000
                                          swPoint.Z = 0#
                                          Set swPoint = SwLine.GetEndPoint2
                                          swPoint.X = 100# / 1000
                                          swPoint.Y = 50# / 1000
                                          swPoint.Z = 0#
                                      End If
                                      If swSkSegment.GetID(0) = 1 Then
                                          Set swPoint = SwLine.GetStartPoint2
                                          swPoint.X = 50# / 1000
                                          swPoint.Y = 100# / 1000
                                          swPoint.Z = 0#
                                          Set swPoint = SwLine.GetEndPoint2
                                          swPoint.X = 100# / 1000
                                          swPoint.Y = 100# / 1000
                                          swPoint.Z = 0#
                                      End If
                                  End Select
                              Next ii
                          End If
                          Set swView = swView.GetNextView
                      Wend
                  
                  
                  End Sub