2
$\begingroup$

I need to find coordinates of points extruded from blender's bezier curve with python. All I know right now is how to evaluate each point on the curve(mathutils.geometry.interpolate_bezier) but I don't know how to find the perpendicular vector with Spline's tilt.

explanation

Basically, I need to find a perpendicular vector with the original vector and tilt in each curve vertex. How do I do that in python?

So far I've only gotten the spline points but not the extrusion, here:

import bpy
import mathutils
interp = mathutils.geometry.interpolate_bezier

class DummyOp(bpy.types.Operator):
    bl_idname = "object.get_bezier"
    bl_label = "Extract Bezier Points"

    def execute(self, context):
        ob = context.object
        dat = ob.data
        bzp = dat.splines[0].bezier_points
        points=interp(bzp[0].co, bzp[0].handle_right, bzp[1].handle_left, bzp[1].co, dat.resolution_u+1)
        print(f"So far I can only extract this data:\n{dat.resolution_u},\nCurve points:")
        for p in points:
            print(p)
        return {'FINISHED'}

def register():
    bpy.utils.register_class(DummyOp)

def unregister():
    bpy.utils.unregister_class(DummyOp)

if __name__ == "__main__":
    register()

    bpy.ops.object.get_bezier()

$\endgroup$
1
  • $\begingroup$ I know this -> bpy.ops.object.convert(target='MESH', keep_original=False) method exists, but I was hoping for a cleaner solution without using bpy.ops. I will use this method for now $\endgroup$ Apr 8, 2020 at 18:12

1 Answer 1

2
$\begingroup$

You can use object.to_mesh():

>>> curve_ob = bpy.context.scene.objects['MyCurve']
>>> me = curve_ob.to_mesh()
>>> me.vertices[0].co
Vector((0.0, -1.0, -0.6200000047683716))

This allocates a mesh object specifically for the prupose of being manipulated using Python. You can then free this extra memory with object.to_mesh_clear().

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .