Finding points on a curve

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

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

Finding points on a curve

Post by aerojockey »


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.


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

Post by jebus »

Posts: 0
Joined: Mon Aug 29, 2011 8:13 am

Post by kestion »

And this should really help

Code: Select all

    #### points from Beziercurve
    #### using an array
    import array
    def getPoints(Curve):
        print("\ngetting points for ",," 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")
first you will need to get your curve which can be found by using the Python Console. Assuming you have some created
<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

Vector((-1.0, 0.0, 0.3692214787006378))

Post Reply