8 Replies Latest reply on Jul 26, 2017 5:21 PM by Ivana Kolin

    Find endpoints of all bend lines in a sheet metal part

    Dennis Beeren

      Dear All,

       

      To have our laser cutter engrave the start and end pieces of specific bend lines, I would like to find both endpoints of all bend lines in a model.

      Is there a way to do this in the sheet-metal model by the use of the API?

       

      I would already be glad if I could get the endpoints of a bunch of selected bend lines.

       

      I attached two picture of the result (EngravingLines.PNG) that I would like to achieve. The original situation is visible in BendLines.PNG.

       

      All thoughts on this are welcome and appreciated!

       

      Best regards,

      Dennis.

        • Re: Find endpoints of all bend lines in a sheet metal part
          Amen Allah Jlili

          The bend lines are in a sketch. You need to flatten the part and then you're able to access it.

          • Re: Find endpoints of all bend lines in a sheet metal part
            Ivana Kolin

            zoiets?

            Option Explicit
              
            Public Sub main()
                Dim swApp As SldWorks.SldWorks
                Dim swPartDoc As SldWorks.ModelDoc2
                Dim swFeature As SldWorks.Feature
                Dim swSubFeature As SldWorks.Feature
            
            
                Dim vSkSegArr As Variant
                Dim vSkSeg As Variant
                Dim swSkSeg  As SldWorks.SketchSegment
                Dim swSkLine As SldWorks.SketchLine
            
            
                Set swApp = Application.SldWorks
                Set swPartDoc = swApp.ActiveDoc
               
                Set swFeature = swPartDoc.FirstFeature
                 
                While Not swFeature Is Nothing
                      
                    Select Case swFeature.GetTypeName2
                        Case "FlatPattern"
                            Set swSubFeature = swFeature.GetFirstSubFeature
                             
                            While Not swSubFeature Is Nothing
                                If swSubFeature.Name Like "*Bend-Lines*" Then
                                    Dim swSketch As Sketch
                                    Set swSketch = swSubFeature.GetSpecificFeature2
                                    vSkSegArr = swSketch.GetSketchSegments
                                    For Each vSkSeg In vSkSegArr
                                        Set swSkSeg = vSkSeg
                                        Select Case swSkSeg.GetType
                                            Case swSketchLINE
                                                Set swSkLine = swSkSeg
                                                ProcessSketchLine swApp, swPartDoc, swSketch, swSkLine
                                        End Select
                                    Next vSkSeg
                                End If
                                Set swSubFeature = swSubFeature.GetNextSubFeature
                            Wend
                    End Select
                    Set swFeature = swFeature.GetNextFeature()
                Wend
            
            
            End Sub
            
            
            Private Sub ProcessSketchLine(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swSketch As SldWorks.Sketch, swSkLine As SldWorks.SketchLine)
                Dim swStartPt As SldWorks.SketchPoint
                Dim swEndPt As SldWorks.SketchPoint
                Dim swStartModPt As SldWorks.MathPoint
                Dim swEndModPt As SldWorks.MathPoint
            
            
                Set swStartPt = swSkLine.GetStartPoint2
                Set swEndPt = swSkLine.GetEndPoint2
                Set swStartModPt = TransformSketchPointToModelSpace(swApp, swModel, swSketch, swStartPt)
                Set swEndModPt = TransformSketchPointToModelSpace(swApp, swModel, swSketch, swEndPt)
                Debug.Print "      Start (sketch)   = (" & swStartPt.X * 1000# & ", " & swStartPt.Y * 1000# & ", " & swStartPt.Z * 1000# & ") mm"
                Debug.Print "      Start (model )   = (" & swStartModPt.ArrayData(0) * 1000# & ", " & swStartModPt.ArrayData(1) * 1000# & ", " & swStartModPt.ArrayData(2) * 1000# & ") mm"
                Debug.Print "      End   (sketch)   = (" & swEndPt.X * 1000# & ", " & swEndPt.Y * 1000# & ", " & swEndPt.Z * 1000# & ") mm"
                Debug.Print "      End   (model )   = (" & swEndModPt.ArrayData(0) * 1000# & ", " & swEndModPt.ArrayData(1) * 1000# & ", " & swEndModPt.ArrayData(2) * 1000# & ") mm"
            End Sub
            
            
            Private Function TransformSketchPointToModelSpace(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swSketch As SldWorks.Sketch, swSkPt As SldWorks.SketchPoint) As SldWorks.MathPoint
                Dim swMathUtil As SldWorks.MathUtility
                Dim swXform As SldWorks.MathTransform
                Dim nPt(2) As Double
                Dim vPt  As Variant
                Dim swMathPt As SldWorks.MathPoint
                nPt(0) = swSkPt.X:      nPt(1) = swSkPt.Y:      nPt(2) = swSkPt.Z
                vPt = nPt
                Set swMathUtil = swApp.GetMathUtility
                Set swXform = swSketch.ModelToSketchTransform
                Set swXform = swXform.Inverse
                Set swMathPt = swMathUtil.CreatePoint((vPt))
                Set swMathPt = swMathPt.MultiplyTransform(swXform)
                Set TransformSketchPointToModelSpace = swMathPt
            End Function