Page 1 of 1
[solved] Add spline with control points via Simple API
Posted: Tue Feb 21, 2023 4:17 pm
by Irene
Hello,
Is it possible to add a spline with control points (instead of fit points) via Simple API?
I am trying to create a script for a sewing pattern drawing. So far it works, but i would need control point splines. The script is created from a C# tool, a kind of PoC for sewing pattern "macros".
Best thanks and regards
Irene
Re: Add spline with control points via Simple API
Posted: Tue Feb 21, 2023 4:31 pm
by andrew
Not directly through the Simple API, but for example like this:
Code: Select all
var sp = new RSpline();
sp.setPeriodic(false); // true for closed, periodic
sp.appendControlPoint(new RVector(x1, y1));
sp.appendControlPoint(new RVector(x2, y2));
...
addShape(sp);
You might want to wrap this into your own function for convenience.
Re: Add spline with control points via Simple API
Posted: Tue Feb 21, 2023 10:12 pm
by Irene
Hello Andrew,
Many thanks for the quick reply

I don't get an error so i suppose it works somehow, but the spline does not get drawn. Is there anything else to be done?
The spline should show up inside the green rectangle.
Code: Select all
var sp = new RSpline();
sp.setPeriodic(false);
sp.appendControlPoint(new RVector(138, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 85));
addShape(sp);
I attach my full script just in case. Adding lines and points works like a charm.
Best thanks and regards
Irene
Re: Add spline with control points via Simple API
Posted: Tue Feb 21, 2023 10:29 pm
by andrew
The spline degree is 3 (cubic) by default which means the spline needs at least 4 control points. You can add another control point or change the degree to quadratic using setDegree:
Code: Select all
var sp = new RSpline();
sp.setPeriodic(false);
sp.setDegree(2);
sp.appendControlPoint(new RVector(138, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 85));
addShape(sp);
Re: Add spline with control points via Simple API
Posted: Wed Feb 22, 2023 8:54 pm
by Irene
Hello Andrew,
Works like a charm, thank you very much
Best regards
Irene
Re: Add spline with control points via Simple API
Posted: Thu Apr 11, 2024 9:56 pm
by Paul D
Very helpful thread. Thanks.
Re: Add spline with control points via Simple API
Posted: Fri Apr 12, 2024 5:54 am
by CVH
May I add that a closed spline with a minimal point count doesn't display correctly immediately after creation.
Although on manual creation the preview looks OK.
Code: Select all
var sp = new RSpline();
sp.setPeriodic(true);
sp.setDegree(2);
sp.appendControlPoint(new RVector(138, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 81.44444));
sp.appendControlPoint(new RVector(129.83333, 85));
addShape(sp);
It shows fine when you save the file and reload it.
https://qcad.org/bugtracker/index.php?d ... sk_id=2453
@Paul D.
Remark that an open spline in degree 2 with 3 control points is a parabola or a part of that.
Regards,
CVH