5 Replies Latest reply on May 26, 2015 11:28 AM by Keith Rice

    Detect Style Spline

    Jonas Jonaitis

      How can I detect if a selected Sketch segment is a Spline or Style Spline?

        • Re: Detect Style Spline
          Keith Rice

          Unless there is some property unique to style splines that you can obtain from ISplineParamData, your only option might be to detect if any construction lines are associated with a particular spline. This wouldn't be very easy in a sketch with lots of segments besides a single style spline, however. You'd have to compare start or end points of the lines and see if they intersect with the style spline.

           

          This can get you started.

           

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swSkSeg As SldWorks.SketchSegment
          Dim vSegs As Variant
          Dim i As Integer
          
          Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              vSegs = swModel.SketchManager.ActiveSketch.GetSketchSegments
              For i = 0 To UBound(vSegs)
                  Set swSkSeg = vSegs(i)
                  Debug.Print swSkSeg.GetType
                  Debug.Print swSkSeg.ConstructionGeometry
              Next i
          End Sub
          

           

          Keith

          SolidWorks API Training

            • Re: Detect Style Spline
              Jonas Jonaitis

              I have thoroughly investigated ISplineParamData before asking this question, but I was not able to find any unique parameter that could distinguish these two types of splines. Your suggested method is not very reliable, because I cannot identify if construction lines that intersect style spline are a part of that spline or if they are drawn by the user.

                • Re: Detect Style Spline
                  Keith Rice

                  Style splines have construction lines starting and ending at control points, and these control points are owned by the same spline segment, AND not all of these control points intersect with the spline segment. I don't think it's even possible to create a regular spline with a combination of construction lines and control points that meets this criteria. Even if it is possible, the likelihood of encountering such a spline might be negligible in your situation, or such a spline might be considered a virtual style spline anyway.

                   

                  Keith

                  SolidWorks API Tutorials

                    • Re: Detect Style Spline
                      Jonas Jonaitis

                      Maybe I am missing something obvious, but here is a simple example where regular spline has construction lines connected to its control points.

                      nbLDS.jpg

                      I have used this code:

                      Dim swApp As SldWorks.SldWorks
                      Dim swModel As SldWorks.ModelDoc2
                      Dim swSkSeg As SldWorks.SketchSegment
                      Dim vSegs
                      Dim vPoints
                      Dim i As Integer, i2 As Integer
                        
                      Sub main()
                          Set swApp = Application.SldWorks
                          Set swModel = swApp.ActiveDoc
                          vSegs = swModel.SketchManager.ActiveSketch.GetSketchSegments
                          For i = 0 To UBound(vSegs)
                              Set swSkSeg = vSegs(i)
                              Select Case swSkSeg.GetType
                                  Case swSketchLINE
                                      Debug.Print ">Line<"
                                      Debug.Print " - " & IIf(swSkSeg.ConstructionGeometry, "Constr", "Non-constr")
                                      Debug.Print " - Start: " & swSkSeg.GetStartPoint2.X & "; " & swSkSeg.GetStartPoint2.Y
                                      Debug.Print " - End: " & swSkSeg.GetEndPoint2.X & "; " & swSkSeg.GetEndPoint2.Y
                                  Case swSketchSPLINE
                                      Debug.Print ">Spline<"
                                      swSkSeg.GetCurve.GetBCurveParams5(False, False, False, False).GetControlPoints vPoints
                                      For i2 = 0 To UBound(vPoints) Step 3
                                          Debug.Print " - Point: " & vPoints(i2) & "; " & vPoints(i2 + 1)
                                      Next i2
                              End Select
                          Next i
                      End Sub
                      

                       

                      and I have got this output:

                      >Line<

                      - Constr

                      - Start: -0.01; 0.02

                      - End: -0.02; 0.02

                      >Line<

                      - Constr

                      - Start: -0.02; 0.02

                      - End: -0.02; 0

                      >Line<

                      - Constr

                      - Start: -0.02; 0

                      - End: -0.01; 0

                      >Line<

                      - Constr

                      - Start: 0.01; 0.02

                      - End: 0.02; 0.015

                      >Line<

                      - Constr

                      - Start: 0.02; 0.015

                      - End: 0.01; 0.01

                      >Line<

                      - Constr

                      - Start: 0.01; 0.01

                      - End: 0.02; 0.005

                      >Line<

                      - Constr

                      - Start: 0.02; 0.005

                      - End: 0.01; 0

                      >Spline<

                      - Point: -0.01; 0.02

                      - Point: -3.66666666666667E-02; 1.66666666666667E-02

                      - Point: 1.66666666666667E-02; 0.01

                      - Point: -3.66666666666667E-02; 3.33333333333334E-03

                      - Point: -0.01; 0

                      >Spline<

                      - Point: 0.01; 0.02

                      - Point: 0.02; 0.015

                      - Point: 0.01; 0.01

                      - Point: 0.02; 0.005

                      - Point: 0.01; 0

                       

                      So, if I understand your suggestion correctly, both of these splines should be identified as Style Splines.

                        • Re: Detect Style Spline
                          Keith Rice

                          In my examination of style and non-style splines, the red points are true control points and the green are not control points. Moreover, the green points are not owned by the spline. Hence a style spline has construction lines that both start and end at control points and those control points are owned by the style spline. Finally, if you need additional criteria, the control points in a style spline do not always intersect the spline segment, whereas in a regular spline they always do. (Let me know if you can think of any exceptions to this last rule.)

                           

                          You have already noticed that you can get the control points owned by a single sketch segment using ICurve::GetBCurveParams5.

                           

                           

                          Keith

                          SolidWorks API Training