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
[solved] Add spline with control points via Simple API
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Re: Add spline with control points via Simple API
Not directly through the Simple API, but for example like this:
You might want to wrap this into your own function for convenience.
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);
Re: Add spline with control points via Simple API
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.
I attach my full script just in case. Adding lines and points works like a charm.
Best thanks and regards
Irene
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);
Best thanks and regards
Irene
- Attachments
-
- Testdrawing.jpg (50.2 KiB) Viewed 2424 times
-
- script.js
- (1.84 KiB) Downloaded 169 times
Re: Add spline with control points via Simple API
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
Hello Andrew,
Works like a charm, thank you very much
Best regards
Irene
Works like a charm, thank you very much
Best regards
Irene
Re: Add spline with control points via Simple API
Very helpful thread. Thanks.
Re: Add spline with control points via Simple API
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.
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
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);
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