## Finding points on a curve

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

aerojockey
Posts: 0
Joined: Mon Jun 19, 2006 1:31 am
Location: St Simons Island GA

### Finding points on a curve

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.

jebus
Posts: 0
Joined: Thu Feb 23, 2006 12:56 pm

kestion
Posts: 0
Joined: Mon Aug 29, 2011 8:13 am
And this should really help

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.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.bezier_points
print("Curve_points = ", Curve_points)

Curve_point0 = Curve_points.co
print("Curve_point0 = ", Curve_point0)

Curve_points.foreach_get('co', Curve_array)
print("Curve_array = ", Curve_array, "\n\n")
``````
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, 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.bezier_points.co
Vector((-1.0, 0.0, 0.3692214787006378))