Problem Creating BSplines from Vertices and doing a path sweep on it

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
browntoastjam
Posts: 37
Joined: Fri Aug 20, 2021 9:51 pm

Problem Creating BSplines from Vertices and doing a path sweep on it

Post by browntoastjam »

Hello All,
I posted this here first and look like this forum may be more appropriate.
https://forum.freecadweb.org/viewtopic.php?f=3&t=73934

I created a bspline from vertices thusly:

Code: Select all

import numpy as np
import Draft
points=30
zpoints=np.linspace(0,2.6,points)
sketch=FreeCAD.getDocument('testbspline').getObjectsByLabel('Sketch')
b=sketch[0].Shape.makeOffset2D(4).discretize(points)
for i,j in enumerate(b):
	j.z=zpoints[i]

spline1 = Draft.make_bspline(b,closed=False)
    
On the 3d vieport, this looks like a legitimate curve.
However, I can't sweep a curve along this bspline.

Can anyone point out what is wrong?

I have attached a minimum working example.

Code: Select all

OS: Ubuntu 20.04.5 LTS (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.21.
Build type: Release
Branch: unknown
Hash: 1282fdb7e8a721e9b411358d68daf8921b0bf50a
Python 3.8.10, Qt 5.12.8, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.2
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4 0.12.3
  * fasteners 0.3.50
  * sheetmetal 0.2.54
  * Defeaturing
  * Curves 0.5.2
  * Behave-Dark-Colors 0.1.1
  * Assembly3 0.11.3
  * kicadStepUpMod 10.16.5
  * PieMenu
  * ProDarkThemePreferencePack 1.0.0
Attachments
testbspline.FCStd
(12.02 KiB) Downloaded 11 times
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Problem Creating BSplines from Vertices and doing a path sweep on it

Post by Chris_G »

I think the sweep operation fails because the sweep path has straight portions where normal vector is undefined.
You can use Part.BRepOffsetAPI.MakePipeShell that is an advanced sweep tool, where you can force a binormal vector.

Code: Select all

import numpy as np
import Draft
points=300
zpoints=np.linspace(0,2.6,points)
sketch=FreeCAD.getDocument('testbspline').getObjectsByLabel('Sketch')
b=sketch[0].Shape.makeOffset2D(4).discretize(points)
for i,j in enumerate(b):
	j.z=zpoints[i]

spline1 = Draft.make_bspline(b,closed=False)
FreeCAD.activeDocument().recompute()

path = Part.Wire(spline1.Shape.Edge1)
profile_obj = FreeCAD.getDocument('testbspline').getObjectsByLabel('Circle')[0]
profile = Part.Wire(profile_obj.Shape.Edge1)

ps = Part.BRepOffsetAPI.MakePipeShell(path)
ps.add(profile)
ps.setBiNormalMode(FreeCAD.Vector(0, 0, 1))
ps.build()
ps.makeSolid()
Part.show(ps.shape())

browntoastjam
Posts: 37
Joined: Fri Aug 20, 2021 9:51 pm

Re: Problem Creating BSplines from Vertices and doing a path sweep on it

Post by browntoastjam »

This works perfectly. Thank you very much.
Chris_G wrote: Mon Nov 28, 2022 10:59 am I think the sweep operation fails because the sweep path has straight portions where normal vector is undefined.
You can use Part.BRepOffsetAPI.MakePipeShell that is an advanced sweep tool, where you can force a binormal vector.

Code: Select all

import numpy as np
import Draft
points=300
zpoints=np.linspace(0,2.6,points)
sketch=FreeCAD.getDocument('testbspline').getObjectsByLabel('Sketch')
b=sketch[0].Shape.makeOffset2D(4).discretize(points)
for i,j in enumerate(b):
	j.z=zpoints[i]

spline1 = Draft.make_bspline(b,closed=False)
FreeCAD.activeDocument().recompute()

path = Part.Wire(spline1.Shape.Edge1)
profile_obj = FreeCAD.getDocument('testbspline').getObjectsByLabel('Circle')[0]
profile = Part.Wire(profile_obj.Shape.Edge1)

ps = Part.BRepOffsetAPI.MakePipeShell(path)
ps.add(profile)
ps.setBiNormalMode(FreeCAD.Vector(0, 0, 1))
ps.build()
ps.makeSolid()
Part.show(ps.shape())

Post Reply