python parameters for bezier/spline objects

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
emills
Posts: 36
Joined: Fri Jan 06, 2012 3:17 am

python parameters for bezier/spline objects

Post by emills »

I'm having a hard time digging up the parameter syntax for the following. I looked on the website and got to a dead end after the scripting pages

Part.BSplineCurve
Part.BsplineSurface
Part.BezierCurve
Part.BezierSurface

When i type "Part." in the interpreter, i can see these options, and hovering the mouse over them tells me, for example, that the bezier surface wants a table of poles/weights. I know what they are, but i don't what format/order to pass them in. I'm guessing either a list of points, Base.Vector(s), or something like that. Do i enter all 16 control points in a row, four lists of four points...where i can set the weights, etc?

Where can i find the parameter definitions and types? Are there commands to explore the objects from the interpreter?
I also probably need to know what type of entity will be returned, and how to make a part that can be shown on screen.
Just to see what would happen i tried the following:

Code: Select all

>>> A = Part.BezierCurve
>>> A
<type 'Part.GeomBezierCurve'>
>>> Part.show(A)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: argument 1 must be Part.TopoShape, not type
>>> Part.Shape(A)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: argument 1 must be list, not type
>>> 
So A got created, but it is apparently a type entity, not a shape, and cannot be cast into a shape. I'm not sure what that means.

Anyway, any help or direction towards help would be greatly appreciated :)
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: python parameters for bezier/spline objects

Post by wmayer »

Code: Select all

import Part
A = Part.BezierCurve()
Part.show(A.toShape())
An example of how to use the b-spline surface:

Code: Select all

# len(knot_u) := nNodes_u + degree_u + 1
# len(knot_v) := nNodes_v + degree_v + 1

degree_u=2
degree_v=2
nNodes_u=5
nNodes_v=5

knot_u=[0,0,0,0.2,0.7,1,1,1]
knot_v=[0,0,0,0.2,0.7,1,1,1]
coor=[[0,0,1],[1,0,2],[2,0,0],[3,0,1],[4,0,2],\
      [0,1,2],[1,1,0],[2,1,0],[3,1,0],[4,1,0],\
      [0,2,0],[1,2,0],[2,2,0],[3,2,0],[4,2,0],\
      [0,3,1],[1,3,0],[2,3,0],[3,3,3],[4,3,0],\
      [0,4,2],[1,4,0],[2,4,0],[3,4,0],[4,4,0]]

bs=Part.BSplineSurface()
bs.increaseDegree(degree_u,degree_v)

id=1
for i in range(0,len(knot_u)-1):
        if knot_u[i+1] > knot_u[i]:
                bs.insertUKnot(knot_u[i],id,0.0000001)

id=1
for i in range(0,len(knot_v)-1):
        if knot_v[i+1] > knot_v[i]:
                bs.insertVKnot(knot_v[i],id,0.0000001)

i=0
for jj in range(0,nNodes_v):
        for ii in range(0,nNodes_u):
                bs.setPole(ii+1,jj+1,FreeCAD.Vector((coor[i][0],coor[i][1],coor[i][2])),1);
                i=i+1;

s=bs.toShape()
Part.show(s)
emills
Posts: 36
Joined: Fri Jan 06, 2012 3:17 am

Re: python parameters for bezier/spline objects

Post by emills »

Awesome, thank you. Can't wait to try it after work.
Post Reply