Hello,
I would like to know if there's a way to find the coordinates of points on a curve (bezier or nurbs, open or closed) from Python. I'm not talking about the control points; I know how to find those. I'm talking about finding the coordinates of points on the curve itself.
Currently what I'm doing it creating mesh from the curve and extracting coordinates of the points on that mesh, which works ok. However, there are two drawbacks:
1. The mesh produced is not fine enough for my indended use
2. For paths, the mesh loses direction information, which I need
Right now, I'm handling problem 1 by subsurfing the extracted mesh; #2 with a shaky hack.
Thanks.
Finding points on a curve
Moderators: jesterKing, stiv
-
- Posts: 0
- Joined: Mon Jun 19, 2006 1:31 am
- Location: St Simons Island GA
And this should really help
http://www.pasteall.org/12757/python
first you will need to get your curve which can be found by using the Python Console. Assuming you have some created
>>>bpy.data.curves
<bpy_collection[3], BlendDataCurves> # or however many you have.
Then check in the 3D viewport what the name of your selected curve is. Mine for example, is BezierCurve
>>> bpy.data.curves['BezierCurve'].splines[0].bezier_points[0].co
Vector((-1.0, 0.0, 0.3692214787006378))
http://www.pasteall.org/12757/python
Code: Select all
#### points from Beziercurve http://www.pasteall.org/12757/python
#### using an array
import array
def getPoints(Curve):
print("\ngetting points for ", C1.name," by array")
Curve_length = len(Curve.splines[0].bezier_points)
print("Curve_length = ", Curve_length)
Curve_array = array.array('f', [0,1,2] * Curve_length)
print ("Curve_array = ", Curve_array)
Curve_points = Curve.splines[0].bezier_points
print("Curve_points = ", Curve_points)
Curve_point0 = Curve_points[0].co
print("Curve_point0 = ", Curve_point0)
Curve_points.foreach_get('co', Curve_array)
print("Curve_array = ", Curve_array, "\n\n")
>>>bpy.data.curves
<bpy_collection[3], BlendDataCurves> # or however many you have.
Then check in the 3D viewport what the name of your selected curve is. Mine for example, is BezierCurve
>>> bpy.data.curves['BezierCurve'].splines[0].bezier_points[0].co
Vector((-1.0, 0.0, 0.3692214787006378))