edit points in a bez curve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Vasten
Posts: 23
Joined: Wed May 18, 2022 9:00 pm

edit points in a bez curve

Post by Vasten »

I can see the points as an array of vectors

Code: Select all

bezobj.Points
[Vector (-26.04, 8.41, 4.0), Vector (-17.19, -1.9, 0.0), Vector (-8.95, -1.39, 0.0), Vector (-12.08, 10.62, 0.0), Vector (-15.2, 22.64, 0.0), Vector (-8.79, 24.22, 0.0), Vector (-0.07, 16.76, 0.0)]
I can pick out a a point

Code: Select all

>>> bez.Points[0]
Vector (-26.04, 8.41, 4.0)
but if i edit one nothing changes and when I check the value it has not changed

Code: Select all

>>> bez.Points[0]=FreeCAD.Vector(0,0,0)
>>> bez.Points
[Vector (-26.04, 8.41, 4.0), Vector (-17.19, -1.9, 0.0), Vector (-8.95, -1.39, 0.0), Vector (-12.08, 10.62, 0.0), Vector (-15.2, 22.64, 0.0), Vector (-8.79, 24.22, 0.0), Vector (-0.07, 16.76, 0.0)]
Am i doing something wrong? are the points actually derived form something else?
Vasten
Posts: 23
Joined: Wed May 18, 2022 9:00 pm

Re: edit points in a bez curve

Post by Vasten »

nevermind

after more testing and trial and error i figured it out

you have to reset the full array

so

Code: Select all

pts=bez.Points
pts[x]=vector(blahblahblah)
bez.Points=pts
this works
User avatar
onekk
Veteran
Posts: 6212
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: edit points in a bez curve

Post by onekk »

Vasten wrote: Tue Jun 21, 2022 7:53 am nevermind

after more testing and trial and error i figured it out

you have to reset the full array

so

Code: Select all

pts=bez.Points
pts[x]=vector(blahblahblah)
bez.Points=pts
this works
Not necessarily, but with "fragments" of code it is difficult to guess on what you are operating.

Plus a little idea of what version of FC are you using will be useful, as something could be changed between versions, and it is not ever true that an user is using latest version (0.20) or maybe even ex stable version (0.19.4), some user are using even old 0.18 version.



a simple:

Code: Select all

dir(Part.BezierCurve)
In Python Console will show that Bezier curves have this methods among others:

Code: Select all

 'setPole', 'setPoles', 'setWeight',
and:

Code: Select all

help(Part.BezierCurve)
will print:

Help on class BezierCurve in module Part:

class BezierCurve(BoundedCurve)
| Describes a rational or non-rational Bezier curve:
| -- a non-rational Bezier curve is defined by a table of poles (also called control points)
| -- a rational Bezier curve is defined by a table of poles with varying weights
|
| Constructor takes no arguments.
|
| Example usage:
| p1 = Base.Vector(-1, 0, 0)
| p2 = Base.Vector(0, 1, 0.2)
| p3 = Base.Vector(1, 0, 0.4)
| p4 = Base.Vector(0, -1, 1)
|
| bc = BezierCurve()
| bc.setPoles([p1, p2, p3, p4])
| curveShape = bc.toShape()
| ...


| insertPoleAfter(...)
| Inserts after the pole of index.
|
| insertPoleBefore(...)
| Inserts before the pole of index.
|
| interpolate(...)
| Interpolates a list of constraints.
| Each constraint is a list of a point and some optional derivatives
| An optional list of parameters can be passed. It must be of same size as constraint list.
| Otherwise, a simple uniform parametrization is used.
| Example :
| bezier.interpolate([[pt1, deriv11, deriv12], [pt2,], [pt3, deriv31]], [0, 0.4, 1.0])
|
...
| removePole(...)
| Removes the pole of index Index from the table of poles of this Bezier curve.
| If this Bezier curve is rational, it can become non-rational.
|
|
....
setPole(...)
| Set a pole of the Bezier curve.
|
| setPoles(...)
| Set the poles of the Bezier curve.
|
| Takes a list of 3D Base.Vector objects.
|
| setWeight(...)
| (id, weight) Set a weight of the Bezier curve.

So there are plenty of information if you know how to get them!

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply