6 Replies Latest reply on Oct 23, 2013 11:24 AM by Matt Fisher

    Testing edges for linearity.

    Matt Fisher

      I have a macro that creates an oriented bounding box around a part given 2 co-planar linear edges as input. I've been testing the edges for linearity with ICurve.IsLine.  My problem is that sometimes the edge curve is a BCurve so IsLine fails. Is there a way to test a BCurve for linearity as a work around?

       

      The selected edges in the following screenshot fail the IsLine test yet the 3 faces shown are planar and mutually perpendicular.

       

      SolidWorks Premium 2013 x64 Edition - [4567-FEELER -3.jpg

        • Re: Testing edges for linearity.
          Keith Rice

          Matt,

           

          I tried these:

           

          1. Getting ICurve::LineParams - didn't work

          2. Selecting the two adjacent edges and checking for perpendicularity using IMeasure::IsPerpendicular - didn't work because it returned false, even though the measure tool when used in the GUI returns true (odd...)

          3. Converted the edge to a sketch segment in a 3D sketch and then tested if that sketch segment was a line (versus a spline) - this did work. So here's the code for that.

           

          =======

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swSelMgr As SldWorks.SelectionMgr

          Dim swEdge As SldWorks.Edge

          Dim swCurve As SldWorks.Curve

          Dim swSketch As SldWorks.Sketch

          Dim swSketchSegment As SldWorks.SketchSegment

          Dim swFeat As SldWorks.Feature

          Dim vSketchSegs As Variant

          Dim i As Integer

          Dim strName As String

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Set swEdge = swSelMgr.GetSelectedObject6(1, -1)

              Set swCurve = swEdge.GetCurve

              If swCurve.isline = False Then

                  swModel.SketchManager.Insert3DSketch (False)

                  Set swSketch = swModel.SketchManager.ActiveSketch

                  Set swFeat = swSketch

                  strName = swFeat.Name

                  swModel.SketchManager.SketchUseEdge2 (False)

                  vSketchSegs = swSketch.GetSketchSegments

                  If IsEmpty(vSketchSegs) = False Then

                      Set swSketchSegment = vSketchSegs(0)

                      If swSketchSegment.GetType = swSketchLINE Then

                          swModel.SketchManager.Insert3DSketch False

                          swModel.Extension.SelectByID2 strName, "SKETCH", 0, 0, 0, False, 0, Nothing, 0

                          swModel.EditDelete

                          swApp.SendMsgToUser "Edge is linear."

                      End If

                  End If

              End If

          End Sub

           

          =======

           

          Keith

          SolidWorks API Tutorials

          • Re: Testing edges for linearity.
            Artem Taturevych

            Because line is a minimal segment between two points I would do the following to identify whether this b-curve or line curve is line:

             

            1) Calculate the distance between end points (vertices of the edge) - this is the length of the line.

            2) Calculate the actual length of the curve: Curve::GetLength3.

            3) Compare #1 and #2. If the comparison satisfies the tolerance the curve is line.

            ____________________________________________________

            Regards,

            Artem Taturevych, Application Engineer at Intercad (Australia)

             

            translationXpert – add-in to translate SolidWorks models

            myIntercad an integrated tool for SolidWorks Professionals

            LinkedIn SolidWorks API Education Group