# Blender Curve API help / equation to 3d space program

Hello,
here’s what I’m looking at :
http://www.blender.org/documentation/249PythonDoc/Curve-module.html
how do I call this “bezList2Curve” function?
I assumed it needed 3 vectors so I made a list of 3 vectors, but the error is :

``````AttributeError:'float' has no attribute 'x'
``````

so… am I plugging the parameters in right?

also, I’m trying to make a script that will take an equation : eg: y = x^2 , and plot the points in 3d space. What’s the best way to go about this?

code is below :

``````from Blender import *
from Blender import Mathutils
'''
how do you call the function bezList2Curve() ?

This is what I'm trying to get the code to do:
# make a new curve
# set variables
# make a new equation eg: y= x^2
# create a new object to store each location
#create an array of these location objects to make a table
# set each point equal to a certain object in the array
# create a 3d (or 2d in 3d space)  object for the curve

is there an easier method than what I'm attempting?
'''
#http://www.blender.org/documentation/249PythonDoc/API_related-module.html
def bezList2Curve(bezier_vecs):
'''
Take a list or vector triples and converts them into a bezier curve object
'''
def bezFromVecs(vecs):
'''
Bezier triple from 3 vecs, shortcut functon
'''
bt= BezTriple.New(                      vecs[0].x, vecs[0].y, vecs[0].z,                        vecs[1].x, vecs[1].y, vecs[1].z,                        vecs[2].x, vecs[2].y, vecs[2].z)

bt.handleTypes= (BezTriple.HandleTypes.FREE, BezTriple.HandleTypes.FREE)
return bt
# create the curve data with one point
cu= Curve.New()
cu.appendNurb(bezFromVecs(bezier_vecs[0])) # we must add a starting point
cu_nurb = cu[0] #get first curve just added in the curve data

i=1 # skip first vector triple because it was used to initialize the cuve
while i&lt;len(bezier_vecs):
bt_vec_triple = bezier_vecs[i]
bt= bezFromVecs(bt_vec_triple)
cu_nurb.append(bt)
i+=1

# add teh curve into the scene
scn = Scene.GetCurrent()
ob = scn.objects.new(cu)
return ob
m =Mathutils
v=[m.Vector(3,2,1), m.Vector(5,5,5),m.Vector(7,-8,7)]

bezList2Curve(v)

``````

-amdbcg

it needs a list of triples, i.e. a list of lists of vectors. It seems you passed it a list of vectors.

well this one is using bezier triples vector

meaning the point + 2 handles for each bezier point in curve

so that’ complicated and creazy but may be usefull to some guy in math

so what i did i change it a little and use poly point instead which dont’ requires triplets only on vector for XYZ point

can you use poly line instead ?

PM me and i’ll take the time to check out and example i did last 2 months
may be can be easier to do and use !

happy blendering

Here’s what I have so far: the method takes an input range and outputs the x and y coordinates.
It runs, everything works great.
Instead of printing out the x and y, how do I get these points (assuming z =0) into 3d space in a mesh?
next question, how do I make edges between them?

``````import Blender, math
from Blender import *
from array import array
a=array('d')
b=array('d')

def x2y(r):               # Create a method
i=0
for k in range(0,r+1,1):
y= pow(k,2)+ 2*k+3     # the equation y= x^2 + 2x+3 , pow =power(x,power)
a.append(y)                # appends y to an array
b.append(k)               # appends x to an array
print "
x =" , k                # outputs data
print "y =" , a[k]

x2y(10)

#######
``````

your not usng curve anymore ?

the array needs 2 values X Y Z
that will give 3d points in space

hope it helps

happy blendering

``````your not usng curve anymore ?
``````

I’m not sure HOW to use curves

but what are you trying to do with this new script ?

i mean a mesh

give the equation i’ll see if can use it in a curve script this weekend may be

can you show a pic of that the curve looks like !

wold be easier to see if it is working or not

can you confirm this is a curve not a 3d surface here ?

salutations

``````but what are you trying to do with this  new  script ?

i mean a mesh
``````

I’m basically trying to make a line or something in the 3d view. Poly curve is my goal but mesh seems a wee bit easier
dunno if that’s the case though - whatt’s the method for a poly curve?

give the equation i’ll see if can use it in a curve script this weekend may be
cool thanks

can you show a pic of that the curve looks like !
sure
it’s a parabola:
http://www.wolframalpha.com/input/?i=y%3D+x^2+%2B+2x%2B3+

can you confirm this is a curve not a 3d surface here ?
confirmed, this is a 2d curve in 3d space, not a 3d surface. (eg: z = 0)

Patrick did some nice work with path generation a while back.

There is a lot of useful code in his script.

parabola

hum ok i may already have one for you

but you may need to scale locate and rotate it

is that good with you ?

i think you can esaily size the base widht and the height
but that’s it after you can scale rotate re locate !

but it may be mesh type i have to check which one i did curve or mesh

salutations

RickyBlender: Okay, cool, thanks
It really doesn’t matter (mesh or curve) - I just want to have an input as an equation and an output to the 3d window
scaling and rotating is fine.

the last one you gave me was okay… but I wasn’t sure of the exact purpose of the script (it looked like it beveled a curve)

EDIT: Thanks RickyBlender for the script, now I just gotta dissect it

Patrick did some nice work with path generation a while back.

Meandering Paths:
http://blenderartists.org/forum/show…eandering+path

There is a lot of useful code in his script
Wow, that’s a lot of code… yes, the method at the end called

``````makeBevObj()
``````

looks promising