10 Replies Latest reply on Apr 18, 2018 9:15 PM by Moon Wang

    problem with get spline params

    Moon Wang

      Hello,everyone.I am now having some poblem with the Api function GetBCurveParams,I want to extract the  params of a spline after I have sktched in Solidworks before.Because the skecth is drawed by myself,so I know the coordinates of the spline's control points.However,I have test the api GetBCurveParams(false/true),GetBCurveParams3(true,false/true,false/true),GetBCurveParams4(true,false,false,false)to get the control points and knot vector in cubic curve ,none of them can accurately does well.For  eample,I drew the spline with 9 control points ,by SplineArray4 = swCurve.GetBCurveParams4(true, false, true, false);I get the array which gives back me 6 control points ,or the knot vector only consists of 0 and 1.I am really puzzled.Can someone give me some hints,thank you

        • Re: problem with get spline params
          Taus Moller

          Posting you example would help diagnose the problem. However i have had issues with this in the past. One thing to note is that when drawing a spline in solidworks you are note actually placing Controls points, but rather points for the spline to pass through. Try right clicking on the spline and select "Display Control Polygon" this will show you the actual control points. This might give you a hint to what is going on

            • Re: problem with get spline params
              Moon Wang

              2018-04-16_215618.png

              So you can see that I am really should get the control points, and I have already set their coordinates

                  • Re: problem with get spline params
                    Moon Wang

                    CODE:

                     

                    object[] skSegments = (object[])swSketch.GetSketchSegments();

                    for (int t = 0; t < SegNum; t++)

                                            {

                                                SketchSegment iSketchSegmengt;

                    int sketchType = iSketchSegmengt.GetType();

                                                if (sketchType == (int)swSketchSegments_e.swSketchSPLINE)

                                                {

                                                   ISketchSpline swSketchSpline;

                                                    swSketchSpline = (ISketchSpline)iSketchSegmengt;

                                                    ICurve swCurve;

                                                    swCurve = iSketchSegmengt.IGetCurve();

                                                    int size=swCurve.IGetBCurveParamsSize(false);

                                                    double[] SplineArray = new double[size];

                                                    SplineArray=swCurve.GetBCurveParams(true);

                    }

                    }

                    /////////////////////////////

                    I don't think that I need get SplineHandles(),don't you think so?

                      • Re: problem with get spline params
                        Taus Moller

                        You are using and obsolete version of GetBCurveParams. If you check the documentation (GetBCurveParams) you will see that it directs you to another method you should use. In fact it has been deprecate a few times. The current one is GetBCurveParams5.

                         

                        Note it returns an ISplineParam you can query for the datapoints.

                         

                        something like this will do the trick:

                        ICurve swCurve;
                        swCurve = seg.IGetCurve();
                        ISplineParamData SplineParams = swCurve.GetBCurveParams5(true,false,false,false);
                        int numpoint = SplineParams.ControlPointsCount;
                        object opoints = new double[numpoint*3];
                        SplineParams.GetControlPoints(out opoints);
                        double[] point = (double[])opoints;
                        
                          • Re: problem with get spline params
                            Moon Wang

                            Thank you for your advice.I have test it,but it turns out that the result is same as before,athough the form of the returned array has changed .If I use swCurve.GetBCurveParams5(true,false,false/true,false), the control points has 6 points,the knot vector has 10 member (0,0,0,0,0.5,0.5,1,1,1,1),If I use swCurve.GetBCurveParams5(true,true,tue,false),the control points has 14 points,knot vector has 18 member.So I think maybe Solidworks api cannot give us right answer....

                              • Re: problem with get spline params
                                Taus Moller

                                I am getting the expected result from GetBCurveParams5. I.e. drawing a style spline with 10 points i get a 30 point array from the ISplineCurveData. I suspect the issue is in the part. If you could post the Solidworks part it would help a lot.

                                  • Re: problem with get spline params
                                    Moon Wang

                                    Taus,

                                    Thank you very much for your testing, I am posting the sldprt(Solidworks 2015) and igs file of the Solidworks part, I appricate your help very much.

                                             Some of my codes is below:

                                                                 ICurve swCurve;

                                                                    swCurve = iSketchSegmengt.IGetCurve();

                                                               

                                                                    ISplineParamData SplineData=null;

                                                                    SplineData = (ISplineParamData)swCurve.GetBCurveParams5(true,false,true,false);

                                                                    int ConNum = SplineData.ControlPointsCount;

                                                                    int KnotNum = SplineData.KnotPointsCount;

                                                                    //double []ConPoints=new double[ConNum];

                                                                    object uConPoints;

                                                                   // double iConPoints;

                                                                    object uKontVector;

                                                                    //object[] KontVector = new object[KnotNum];

                                                                    SplineData.GetControlPoints(out uConPoints);

                                                                    //SplineData.IGetControlPoints(ConNum, out iConPoints);

                                                                    SplineData.GetKnotPoints(out uKontVector);

                                     

                                                                    int size3 = swCurve.IGetBCurveParamsSize3(true, false, false);

                                                                    double[] SplineArray3 = new double[size3];

                                                                    SplineArray3 = swCurve.GetBCurveParams4(true, false, false, false);

                                      • Re: problem with get spline params
                                        Taus Moller

                                        A bit of experimentation gave some quite confusing results for me. I tried deleting everything but the spline in question and to see what the result would be. I got a similar result to you.

                                         

                                        Then i tried creating a new style spline to see if it displayed the same behavior. This one returned the expected number of control points at first. However i found that moving around the control points of the spline would change the number of points returned by SplineParamData.GetControlPoints.

                                         

                                        My best guess is that Solidworks tries to provide some "user friendly" handles that look like control points but does some secret stuff underneath. I would try to contat API support with the issue, as GetBCurveParams5 certainly does not behave as one would expect