Documentation for b-spline in Part Workbench

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
Charles
Posts: 5
Joined: Fri Aug 29, 2014 9:04 pm

Documentation for b-spline in Part Workbench

Post by Charles »

OS: Ubuntu 14.04.1 LTS
Word size: 64-bit
Version: 0.14.3702 (Git)
Branch: releases/FreeCAD-0-14
Hash: b3368125c63289ec8ce9faec2b2ae4c78d436406
Python version: 2.7.6
Qt version: 4.8.6
Coin version: 4.0.0a
SoQt version: 1.6.0a

I have seen some tantalizing bits of code using splines in the part workbench
(from http://www.freecadweb.org/wiki/index.ph ... ectellipse):

def execute(self, fp):
r1=fp.a
r2=fp.b
s=fp.n
z=0.0
p=1.0
####w=2**0.5/2.0 #Ellipse
w=2**0.5/2.0/(1-s**p)
curve=Part.BSplineCurve()
curve.setPeriodic()
curve.increaseDegree(2) #quadratic
curve.insertKnots([i*1.0/(4) for i in (1,2,3)],[2]*(3)) #5Knots 8 Poles
curve.setPole(1,FreeCAD.Vector(0,-r2,z),1)
curve.setPole(2,FreeCAD.Vector(-r1,-r2,z),w)
curve.setPole(3,FreeCAD.Vector(-r1,0,z),1)
curve.setPole(4,FreeCAD.Vector(-r1,r2,z),w)
curve.setPole(5,FreeCAD.Vector(0,r2,z),1)
curve.setPole(6,FreeCAD.Vector(r1,r2,z),w)
curve.setPole(7,FreeCAD.Vector(r1,0,z),1)
curve.setPole(8,FreeCAD.Vector(r1,-r2,z),w)
if fp.createFace == True:
fp.Shape = Part.Face(Part.Wire(curve.toShape()))
else:
fp.Shape = curve.toShape()

I've been using the Spyder IDE for debugging and code experimentation. I've been able to get
Part.Part.BSplineCurve() to create a <BSplineCurve object>. It doesn't take any args in the
construction, however, and the above code looks like one has to create the <BSplineCurve object>,
then specify it. I don't find any documentation in the wiki, forums, internet search for how to do this
in the Part Workbench. Searches only appear to turn up Draft Workbench examples, which allow one
to specify the details at the time of construction, thus a different beastie, it seems.

Is there any detailed documentation of how the b-spline works in the Part Workbench, or do I just
need to experiment until I figure out how the commands work?
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: Documentation for b-spline in Part Workbench

Post by mario52 »

hi
here one macro with Part.BSplineCurve()
one discussion Closed BSplines with Same First & Last Point
the wiki page of Draft_BSpline an one example of macro
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply