Add a line to a spline

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Vincent B
Veteran
Posts: 4735
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Add a line to a spline

Post by Vincent B »

I would like append a line to Bspline but I don't know how to.

Code: Select all

curve = Part.BSplineCurve(matriz)
          if obj.CreateFace == True:
                curve = Append.line((x0,y0,0),(x,y,0))
                sh = Part.Face(Part.Wire(curve.toShape()))
of course append.line doesn't exist, but which code to do that?
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Add a line to a spline

Post by Chris_G »

Hi,
I have not tested, but this should work :

Code: Select all

curve = Part.BSplineCurve(matriz)
          if obj.CreateFace == True:
          	line = Part.BSplineCurve([FreeCAD.Vector(x0,y0,0),FreeCAD.Vector(x,y,0)])
          	curve.join(line)
                sh = Part.Face(Part.Wire(curve.toShape()))
User avatar
Vincent B
Veteran
Posts: 4735
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Re: Add a line to a spline

Post by Vincent B »

thanks it's working.
but it's not possible to add a true line with a spline?
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Add a line to a spline

Post by Chris_G »

What is your goal ?
If you can stay at the topology level, you can create a wire made of edges supported by different types of geometry (line, Bspline curve, conics, etc ...)
This way, you don't loose the geometric type of the edges.

Code: Select all

line_segment = Part.LineSegment(v1,v2)
bs_curve = Part.BsplineCurve(poles)
# we go to topology level
edge1 = line_segment.toShape()
edge2 = bs_curve.toShape()
wire = Part.Wire([edge1, edge2])
But at the geometry level, there is no way to create "compound" objects (made of multiple sub-entities).
So fusing several geometry objects into one, can only be done by converting them to a common geometry type (BSpline curve being the most general type, that can replace lines and conics, lossless).
User avatar
Vincent B
Veteran
Posts: 4735
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Re: Add a line to a spline

Post by Vincent B »

thanks a lot Chris.
It's exactly I didn't understand.
Post Reply